sqlite

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: MIT Imports: 15 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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

func Open(path string) (store.Store, error)

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

func (s *Store) Append(ctx context.Context, id string, ev ...weft.Event) error

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

func (s *Store) Delete(ctx context.Context, id string) error

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

func (s *Store) Get(ctx context.Context, id string) (store.RunRecord, error)

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).

func (*Store) List

func (s *Store) List(ctx context.Context, q store.Query) (store.Page, error)

List pages runs newest first without events (and without decoded results — the list view reads the denormalized steps and usage; Get returns everything).

func (*Store) Save

func (s *Store) Save(ctx context.Context, r store.RunRecord) error

Save upserts the runs row and appends any events of r not yet present (by position). steps and usage are denormalised from the result for the list view.

Jump to

Keyboard shortcuts

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