Documentation
¶
Overview ¶
Package sqlitedb opens and migrates the daemons' SQLite databases with the connection settings their schemas rely on. Production code, the checkers and the tests all open SQLite through it, so every database is configured the same way.
Index ¶
Constants ¶
const BusyTimeoutMS = 1000
BusyTimeoutMS is how long a connection waits for a lock held by another process, such as a checker or an operator command, before failing.
const Latest int64 = math.MaxInt64
Latest asks Migrate to apply every pending migration.
Variables ¶
This section is empty.
Functions ¶
func Migrate ¶ added in v0.3.0
Migrate applies the pending goose migrations in migrations to db, up to and including version upTo (Latest for all of them), and reports the version the database records afterwards. Each migration commits on its own, so when one fails the earlier ones stay applied; Migrate then still reports the version recorded, or -1 when it cannot read it, together with the error. Migrate leaves db open for the caller to close.
func Open ¶
Open opens an existing database for reading and writing. SQLite enforces foreign keys only on connections that enable them, and the schemas declare references and cascades, so every connection enables them. mode=rw never creates a missing file unless Create is given, and the file URI keeps filename characters out of the options. The pool holds one connection: SQLite has a single writer.
Types ¶
type Option ¶ added in v0.3.0
type Option func(*options)
Option adjusts how Open opens a database.
func BusyTimeout ¶ added in v0.3.0
BusyTimeout replaces BusyTimeoutMS for a connection that must wait longer, such as a test that races writers on separate handles.
func Create ¶ added in v0.3.0
func Create() Option
Create lets Open create the database file when it is absent. Only code that makes a new database, such as fresh-state setup, schema checks and tests, uses it; daemons open files that already exist.
func ReadOnly ¶ added in v0.3.0
func ReadOnly() Option
ReadOnly opens the database without writing to it: the file is opened read-only and the connection refuses statements that would modify it, so a checker neither upgrades nor journals the file it inspects.
func WithoutSync ¶ added in v0.3.0
func WithoutSync() Option
WithoutSync disables fsync (synchronous=OFF). Locking and journaling are unchanged, but a committed transaction may be lost on power failure, so only tests use it, where fsync otherwise dominates fixture cost on the CI container's overlay filesystem.