sqlite

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 9, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package sqlite implements engine.CheckpointStore on top of SQLite.

The driver is modernc.org/sqlite (pure Go, no cgo) so this backend works on every Go platform without a C toolchain. The store is suitable for single-process daemons (vesseld), embedded examples, and tests; for multi-writer workloads use the postgres backend.

Usage

store, err := sqlite.Open(ctx, "file:checkpoints.db?_pragma=journal_mode(WAL)")
if err != nil { return err }
defer store.Close()

// Wire into engine.LoadAndResume / engine.Host.Checkpointer.

Schema

The store keeps the latest checkpoint per ExecID. Older checkpoints for the same exec id are overwritten in place (UPSERT). Callers that need a full history should write their own append-only table — checkpoints are the engine's "where to resume from" record, not an audit log.

Schema is created idempotently by Open; it is also exposed as [Migrate] for callers that want to run the migration explicitly (e.g. before a rolling deploy).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*config)

Option configures Open / Wrap.

func WithTable

func WithTable(name string) Option

WithTable overrides the table name (default "engine_checkpoints"). Useful for multi-tenant deployments that namespace tables per vessel.

type Store

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

Store persists engine.Checkpoint records in a SQLite database. One row per ExecID; Save UPSERTs the latest snapshot. Safe for concurrent use across goroutines (database/sql handles pooling).

func Open

func Open(ctx context.Context, dsn string, opts ...Option) (*Store, error)

Open creates a Store backed by a fresh database/sql connection pool against dsn. The Store takes ownership of the pool — closing the Store closes the pool. Migrations are run synchronously before Open returns.

dsn is passed verbatim to modernc.org/sqlite; common forms:

  • "file:checkpoints.db?_pragma=journal_mode(WAL)" — on-disk WAL
  • "file::memory:?cache=shared" — in-memory shared (for tests)

func Wrap

func Wrap(db *sql.DB, opts ...Option) *Store

Wrap builds a Store on top of an existing *sql.DB. The caller retains ownership of db; closing the Store does not close the underlying pool. Migrate must be called before any Save / Load when callers use Wrap.

func (*Store) Close

func (s *Store) Close() error

Close releases resources owned by the Store. Safe to call repeatedly; only the first call has an effect when the Store owns its DB.

func (*Store) Delete

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

Delete removes the checkpoint for execID. Missing exec ids are a no-op (no error). Implements engine.CheckpointDeleter.

func (*Store) List

func (s *Store) List(ctx context.Context) ([]string, error)

List enumerates persisted exec ids. Implements engine.CheckpointLister.

func (*Store) Load

func (s *Store) Load(ctx context.Context, execID string) (*engine.Checkpoint, error)

Load returns the latest checkpoint for execID, or (nil, nil) if none exists.

func (*Store) Migrate

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

Migrate creates the checkpoint table if it does not yet exist. Run automatically by Open; expose for callers that build the Store via Wrap.

func (*Store) Save

func (s *Store) Save(ctx context.Context, cp engine.Checkpoint) error

Save persists cp, overwriting any existing record with the same ExecID.

Jump to

Keyboard shortcuts

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