sqlite

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 13, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package sqlite implements store.Store on SQLite via a pure-Go driver.

Two design points are deliberate and load-bearing:

  • The driver is modernc.org/sqlite (no cgo), because "one static binary, no separate service" is a stated property of the product. A cgo driver would trade that away for marginal speed.
  • There are two connection pools. Writes go through a pool capped at ONE connection, which serializes them at the pool and removes the `SQLITE_BUSY` / "database is locked" failure mode entirely once the executor runs multiple workers. Reads use a normal pool and run concurrently under WAL.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExpectedSchemaVersion

func ExpectedSchemaVersion() (int, error)

ExpectedSchemaVersion is the highest migration this binary ships.

Types

type DB

type DB struct {
	// contains filtered or unexported fields
}

DB is the SQLite-backed store.

func Open

func Open(path string, opts Options) (*DB, error)

Open prepares the database at path, creating it if needed. Use ":memory:" for tests; that mode collapses to a single shared connection because an in-memory database is per-connection.

func (*DB) Close

func (d *DB) Close() error

func (*DB) Migrate

func (d *DB) Migrate(ctx context.Context) error

Migrate applies pending migrations. Each runs in its own transaction and records its version, so a partially-applied set is resumable rather than requiring a manual repair.

func (*DB) Path

func (d *DB) Path() string

Path reports the on-disk location, for diagnostics.

func (*DB) Read

func (d *DB) Read(ctx context.Context, fn func(context.Context, store.Queries) error) error

Read runs fn against the read pool.

func (*DB) SchemaVersion

func (d *DB) SchemaVersion(ctx context.Context) (int, error)

SchemaVersion reports the highest applied migration, or 0 on a fresh database. It reads through the read pool, so a read-only command can check the schema without taking a write lock — which matters because the daemon may hold the writer while the CLI runs.

func (*DB) WithTx

func (d *DB) WithTx(ctx context.Context, fn func(context.Context, store.Tx) error) error

WithTx runs fn in a write transaction.

type Options

type Options struct {
	// ReadConns caps the read pool. Defaults to 8.
	ReadConns int
	// BusyTimeout is how long a statement waits on a lock before erroring.
	// Defaults to 5s. With a single-writer pool this should never be hit from
	// inside one process; it matters when a second process (the CLI) attaches.
	BusyTimeout time.Duration
}

Options configures the store. The zero value is usable.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL