Durable database transactions
Database supplies SQLite storage with explicit transaction ownership. A transaction commits durable intent or rolls back the complete change when an exception escapes.
from pathlib import Path
from skulk_capability_sdk.database import Database
journal = Database(
Path(installation_directory) / "jobs.sqlite",
"CREATE TABLE IF NOT EXISTS jobs (id TEXT PRIMARY KEY, state TEXT NOT NULL);",
)
with journal.transaction() as connection:
connection.execute(
"INSERT INTO jobs(id, state) VALUES (?, ?)",
(operation_id, "queued"),
)
Keep the database in the installation’s protected directory. The SDK opens one connection per transaction, uses immediate transaction ownership, and requests durable synchronization. An optional observed-time callback supplies a consistent clock for SQL observations.
ownership() fences a complete reconciliation across processes. It has a bounded lock-acquisition window and raises Denied when the journal remains busy. Keep external network calls outside a short SQLite transaction; reserve intent first, perform the effect under the operation contract, then record the outcome.