Documentation
¶
Overview ¶
Package sqlite opens the SQLite databases hive and Hive Desktop keep, with the DSN and pool settings every caller must agree on.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AmbientTx ¶ added in v0.63.0
AmbientTx returns the transaction that WithinTx opened on pool and attached to ctx, if there is one.
func Open ¶
Open opens the database at path in WAL mode with foreign keys on, applies the pool settings, and pings it. The caller owns migrations and defaults.
Write transactions begin with BEGIN IMMEDIATE (_txlock=immediate). Several writers, in one process or across the CLI and the desktop, run transactions that read before they write. With the driver default (deferred), two such transactions can both hold a read lock and then both try to upgrade to the write lock. SQLite resolves that deadlock by returning SQLITE_BUSY at once and ignoring busy_timeout, because waiting could never succeed. IMMEDIATE takes the write lock up front, so a second writer waits on busy_timeout instead of failing.
func WithinTx ¶ added in v0.63.0
WithinTx runs fn inside a transaction on pool. When ctx already carries one for pool, fn joins it; otherwise WithinTx begins one and hands fn a context that carries it. Only the call that began the transaction commits it or, when fn fails, rolls it back.
Joining is required, not an optimization. Open sets _txlock=immediate, so a nested BEGIN IMMEDIATE waits out busy_timeout for the write lock its own caller holds and then fails with SQLITE_BUSY.