Help us shape the future of Go! Take the 2026 Go Developer Survey

sqlite

package
v0.1.0-alpha.9 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package sqlite implements Sigil storage on a local SQLite database. It requires CGO and the bundled mattn/go-sqlite3 driver. Open takes a path, owns the pool and claims the whole file. New borrows a pool the host opened with DSN on the database its own tables already live in, and then claims only the reserved "auth_" prefix, the relations plugins register and the indexes and triggers attached to those; everything else stays the host's. Apply explicitly migrates and Check verifies schema history and configuration. Security operations use BEGIN IMMEDIATE and serialize writers across processes. ApplyPlugins serves adapter contract version 1: plugins that declare explicit SQLite migrations install here, and plugins that declare none are rejected rather than falling back to PostgreSQL SQL. See docs/sqlite-adapter.md for concurrency and deployment restrictions.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrPending = errors.New("sqlite: core migrations pending")
	ErrSchema  = errors.New("sqlite: incompatible or altered core schema")
)
View Source
var ErrPluginPending = errors.New("sqlite: plugin migrations pending")
View Source
var ErrPluginSchema = errors.New("sqlite: incompatible plugin history, ownership or schema")

Functions

func DSN

func DSN(path string) (string, error)

DSN renders the only driver configuration this adapter accepts, so a host opening its own pool for New does not have to restate the options by hand. The zero busy timeout is deliberate: the adapter owns context-aware lock acquisition, and a driver-side wait would ignore context cancellation.

Types

type Migration

type Migration struct {
	Version             int
	Name, SQL, Checksum string
}

func Migrations

func Migrations() []Migration

Migrations returns the embedded core migrations in order. Each history row records a version, name and the hex SHA-256 of that SQL.

type PluginTx

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

PluginTx shares the core transaction and its failure state. Binding acquires the database writer lock before any plugin reads, including anonymous flows.

func (*PluginTx) Dialect

func (*PluginTx) Dialect() storage.Dialect

func (*PluginTx) Exec

func (p *PluginTx) Exec(q string, args ...any) (int64, error)

func (*PluginTx) Scan

func (p *PluginTx) Scan(q string, args []any, dest ...any) error

func (*PluginTx) Table

func (p *PluginTx) Table(name string) (string, error)

type Store

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

Store reaches the database through a pool it either owns or borrows. All connections enforce foreign keys, WAL and FULL synchronous durability. Apply explicitly installs migrations; Check never changes the schema.

Open takes a filesystem path, never a SQLite DSN, and owns both the pool and the whole file: any object it does not recognise fails the schema check. New borrows a pool on a database the host also uses for its own tables, and then claims only the reserved prefix and the names plugins registered.

func New

func New(db *sql.DB) (*Store, error)

New borrows a pool the host already opened on its own database, so Sigil needs no second file. The host keeps ownership: Close leaves the pool open and pool sizing stays the host's decision. Open that pool with DSN; Check rejects a pool configured any other way rather than running without the guarantees the adapter depends on. Sigil claims the reserved "auth_" prefix and the relation names its plugins declare; every other object in the database stays the host's, unread and unreported. SQLite still admits one writer per database, so a host write transaction and a Sigil write transaction on different connections block each other: never call a Sigil write from inside an open host write transaction.

func Open

func Open(path string) (*Store, error)

func (*Store) Apply

func (s *Store) Apply(ctx context.Context) error

Apply atomically installs the pending embedded core migrations and their checksum history. It is idempotent, serializes across processes and refuses drift/future versions.

func (*Store) ApplyPlan

func (s *Store) ApplyPlan(ctx context.Context, registry plugin.Registry, plan storage.MigrationPlan) error

ApplyPlan applies a reviewed plan, refusing with storage.ErrPlanChanged and changing nothing unless the plan was made by these declarations and every owner is still at its recorded version. Each comparison happens inside the immediate transaction that applies. Core and plugins commit separately, as Apply and ApplyPlugins do.

func (*Store) ApplyPlugins

func (s *Store) ApplyPlugins(ctx context.Context, registry plugin.Registry) error

ApplyPlugins explicitly applies the compiled registry in dependency order. Core must be installed first. All enabled upgrades commit atomically.

func (*Store) AuditEvents

func (s *Store) AuditEvents(ctx context.Context, q storage.AuditQuery) ([]storage.AuditEvent, error)

func (*Store) Capabilities

func (*Store) Capabilities() storage.Capabilities

func (*Store) Check

func (s *Store) Check(ctx context.Context) error

Check verifies configuration, exact migration history and the installed DDL. A store from Open requires a dedicated file and fails closed on any unowned table. A store from New inspects only the relations Sigil owns, and leaves the host's own tables in the same database unread.

func (*Store) CheckPlugins

func (s *Store) CheckPlugins(ctx context.Context, schemas []storage.PluginSchema) error

func (*Store) ClaimDelivery

func (s *Store) ClaimDelivery(ctx context.Context) (d storage.Delivery, err error)

func (*Store) CleanupDeliveries

func (s *Store) CleanupDeliveries(ctx context.Context, limit int) (n int64, err error)

func (*Store) Close

func (s *Store) Close() error

Close releases a pool this adapter opened. A borrowed pool is the host's to close, once its own work and Sigil's have both stopped.

func (*Store) ConsumeAbuse

func (s *Store) ConsumeAbuse(ctx context.Context, budgets []storage.AbuseBudget) (retry time.Duration, err error)

func (*Store) FinishDelivery

func (s *Store) FinishDelivery(ctx context.Context, id string, attempt int, delivered bool) error

func (*Store) LiveDeliveries

func (s *Store) LiveDeliveries(ctx context.Context, afterID string, limit int) ([]storage.Delivery, error)

func (*Store) Plan

func (s *Store) Plan(ctx context.Context, registry plugin.Registry) (storage.MigrationPlan, error)

Plan returns the inspectable plan of what Apply and then ApplyPlugins with this registry would execute: the core schema if it is not installed, then each enabled plugin's pending versions in dependency order, with the SQLite bodies and the checksums the ledger records. It is read-only and validates what the applies validate. Before core is installed no plugin can be, so every plugin starts at version zero once its relation names are shown to be free. Over an older core, the plan moves core forward before any plugin.

func (*Store) PruneAuditEvents

func (s *Store) PruneAuditEvents(ctx context.Context, before time.Time, limit int) (n int64, err error)

func (*Store) PruneExpired

func (s *Store) PruneExpired(ctx context.Context, before time.Time, limit int) (out storage.Pruned, err error)

func (*Store) RecordAuditEvent

func (s *Store) RecordAuditEvent(ctx context.Context, e storage.AuditEvent) error

func (*Store) ReplaceDeliveryPayload

func (s *Store) ReplaceDeliveryPayload(ctx context.Context, id string, expected, replacement storage.Material) error

func (*Store) WithinTx

func (s *Store) WithinTx(ctx context.Context, fn func(storage.Tx) error) error

Jump to

Keyboard shortcuts

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