Documentation
¶
Overview ¶
Package storage wraps the local SQLite database (WAL mode).
A pure-Go driver (modernc.org/sqlite) is used so the binary cross-compiles to linux/arm64 without a C toolchain, which the design doc requires for deploying to Orange Pi / Raspberry Pi nodes.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Migrate ¶
Migrate applies pending schema migrations and advances PRAGMA user_version. It is safe to call repeatedly: already-applied versions are skipped.
Migrations are defined in migrations.go. Each migration runs in its own BEGIN IMMEDIATE transaction and updates user_version on success, so a partially failed run can be retried without double-applying earlier steps — and two handles migrating the same file serialize on the reserved lock instead of colliding at commit.
A database whose user_version is ahead of this binary's migration list is an error, not a no-op: running an old binary against a newer schema would silently corrupt assumptions the newer schema already made.
func Now ¶
func Now() int64
Now returns Unix seconds; SQLite timestamps are stored as epoch seconds.
func Open ¶
Open opens (or creates) the SQLite database at path in WAL mode. The parent directory is created automatically so callers never hit SQLITE_CANTOPEN (error 14) because a parent directory was missing — this is the most common first-run failure when `panda` is invoked from any directory other than the project root.
Types ¶
type Migration ¶
type Migration struct {
Version int
Name string
Apply func(MigrationExec) error
}
Migration is a single schema change identified by a monotonic version. Each migration runs inside its own BEGIN IMMEDIATE transaction (see migrate.go) and, on success, advances PRAGMA user_version to its Version. The Apply body receives a MigrationExec (Exec/Query/QueryRow) rather than a *sql.Tx: the transaction is driven explicitly on the pooled connection.
type MigrationExec ¶ added in v0.0.7
type MigrationExec interface {
Exec(query string, args ...any) (sql.Result, error)
Query(query string, args ...any) (*sql.Rows, error)
QueryRow(query string, args ...any) *sql.Row
}
MigrationExec is the statement surface a migration body needs: Exec, Query, QueryRow — nothing else is used by any of the migrateVN functions. It exists so a migration can run inside an explicit BEGIN IMMEDIATE transaction driven on the raw *sql.DB (see runMigration), which db.Begin() cannot produce (it only issues a plain BEGIN).