Documentation
¶
Overview ¶
Package db opens the SQLite database, applies embedded goose migrations and provides transaction helpers shared by the repositories in internal/store.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DSN ¶
DSN builds the modernc.org/sqlite connection string for path with the pragmas every connection must carry.
func IsCheckViolation ¶
IsCheckViolation reports whether err is a CHECK constraint failure.
func IsForeignKeyViolation ¶
IsForeignKeyViolation reports whether err is a FOREIGN KEY constraint failure.
func IsUniqueViolation ¶
IsUniqueViolation reports whether err is a UNIQUE or PRIMARY KEY constraint failure.
Types ¶
type DB ¶
DB wraps *sql.DB for the panel database.
func Open ¶
Open opens (creating if needed) the SQLite database at path and verifies the connection. It does not run migrations; call Migrate.
func (*DB) LatestSchemaVersion ¶
LatestSchemaVersion returns the newest embedded migration version.
func (*DB) Migrate ¶
func (d *DB) Migrate(ctx context.Context) ([]MigrationResult, error)
Migrate applies all pending migrations and returns those applied.
func (*DB) SchemaVersion ¶
SchemaVersion returns the current goose schema version (0 when unmigrated).
type MigrationResult ¶
MigrationResult describes one applied migration.
type Options ¶
type Options struct {
// MaxOpenConns caps the pool (default 8). WAL allows concurrent readers;
// writers are serialized by SQLite (BEGIN IMMEDIATE + busy_timeout).
MaxOpenConns int
// BusyTimeout is how long a writer waits for the lock (default 5s).
BusyTimeout time.Duration
}
Options tune Open. The zero value is suitable for production.
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 the subset of *sql.DB / *sql.Tx used by repositories, so the same repository code runs inside or outside a transaction.