Documentation
¶
Overview ¶
Package sqlite is the store's durable backend: run records in a single SQLite file on the CGO-free modernc.org/sqlite driver, the same choice Crush made. One database handle serves a process — the recorder is the only writer in weft dev's, and WAL lets a reader in another process (the Inspector) read concurrently through its own Open.
Index ¶
- Variables
- func Open(path string) (store.Store, error)
- type Store
- func (s *Store) Append(ctx context.Context, id string, ev ...weft.Event) error
- func (s *Store) Delete(ctx context.Context, id string) error
- func (s *Store) Get(ctx context.Context, id string) (store.RunRecord, error)
- func (s *Store) List(ctx context.Context, q store.Query) (store.Page, error)
- func (s *Store) Save(ctx context.Context, r store.RunRecord) error
Constants ¶
This section is empty.
Variables ¶
var ErrNewerSchema = errors.New("sqlite: database schema is newer than this weft")
ErrNewerSchema is returned by Open when the file's schema_migrations is ahead of this binary's highest migration: a database written by a newer weft fails loudly instead of running nothing and saying nothing (LangGraph's Postgres saver is the cautionary tale, ADR 0010 §2.3).
Functions ¶
func Open ¶
Open opens (creating if needed) the database at path and brings its schema up to date. ":memory:" works — an in-process database for tests. Connections carry synchronous=NORMAL, busy_timeout=30000, foreign_keys=ON, and immediate write transactions (preventing deferred-to-writer upgrade deadlocks — Crush's set), and the handle allows a single connection so every write is serialized. WAL is not a connection pragma here: it is a persistent property of the file, switched once by the first Open (setWAL) — the DSN-pragma form races on a fresh file, where concurrent mode switches take an exclusive lock SQLite does not take the busy handler's patience for.
Types ¶
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is a SQLite-backed store.Store. Create it with Open; the zero value is not usable.
func (*Store) Append ¶
Append adds events in arrival order and bumps the heartbeat — one transaction, the hot path. INSERT OR IGNORE keeps an ordinal collision (a replayed batch racing a committed one) a no-op instead of an error; ordinals are assigned under the handle's single serialized write connection, so two appends cannot compute the same base.
func (*Store) Delete ¶
Delete removes the run and its events (the FK cascades); children survive with parent_id set to NULL by the FK's ON DELETE SET NULL.
func (*Store) Get ¶
Get returns the whole record. An event whose type this weft does not know fails with store.ErrUnknownEvent naming it and the run — loud over silent (ADR 0010 §2.5).