Documentation
¶
Overview ¶
Package db opens otag's SQLite database and applies embedded migrations.
Index ¶
Constants ¶
const TimeFormat = "2006-01-02T15:04:05.000Z"
TimeFormat is the layout of every timestamp column.
Variables ¶
var ErrNotMigrated = errors.New("database missing or not migrated to this binary's schema")
ErrNotMigrated is returned with Options.NoMigrate when the database is missing or has an older schema than this binary.
Functions ¶
func IsUniqueViolation ¶
IsUniqueViolation reports whether err is a UNIQUE/PRIMARY KEY constraint failure.
func OpenReadOnly ¶ added in v0.1.1
OpenReadOnly opens an existing database for a look that writes nothing at all (mode=ro, query_only, immutable): it is never created, migrated or chmod-ed, and not even a -wal or -shm file is made. immutable skips SQLite's locking and the WAL, so a concurrent writer's latest commits may be missing: callers use it for hints (the setup wizard before the user agreed to anything) and check again with Open.
Types ¶
type DB ¶
type DB struct {
*sql.DB
Path string
// Version is the schema version found in the file; Latest is what this binary knows.
Version, Latest int
// contains filtered or unexported fields
}
DB is an open otag database.
func Open ¶
Open opens (creating if needed) the database at path and migrates it to the latest schema. If the file's schema is newer than this binary, the DB is opened with mode=ro and every Tx call fails with SCHEMA_TOO_NEW.
type Options ¶
type Options struct {
// BusyTimeout bounds how long a statement waits for a lock (default 10s). The hook
// bridge uses a short one so a locked database never stalls a harness.
BusyTimeout time.Duration
// NoMigrate never creates or migrates the database: a missing file or an older
// schema is ErrNotMigrated. For hot paths (the statusLine wrapper) that must never
// take the migration's write lock.
NoMigrate bool
}
Options tune a connection.
type Querier ¶
type Querier interface {
ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
}
Querier is satisfied by *sql.DB, *sql.Conn and *sql.Tx.