sqlite

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package sqlite provides a durable SQLite-backed EventStore implementation. Uses modernc.org/sqlite (pure Go, no cgo). WAL mode and PRAGMA synchronous=FULL provide crash safety. Single-writer per loop is enforced by expectedLastSeq optimistic concurrency.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Store)

Option configures the Store.

func WithSynchronous

func WithSynchronous(mode string) Option

WithSynchronous sets the SQLite synchronous mode (default: FULL). Use "NORMAL" for better performance at the cost of some durability guarantee (still crash-safe with WAL in most cases).

type Store

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

Store is the SQLite-backed EventStore. Thread-safe (SQLite handles concurrent access).

func Open

func Open(path string, opts ...Option) (*Store, error)

Open opens or creates a SQLite database at path and runs migrations.

func (*Store) Append

func (s *Store) Append(ctx context.Context, id event.LoopID, expectedLastSeq uint64, evs []event.Envelope) error

Append appends evs to the event log. Returns ErrConflict if expectedLastSeq is wrong.

func (*Store) Close

func (s *Store) Close() error

Close closes the underlying database connection.

func (*Store) Get

func (s *Store) Get(ctx context.Context, key string) ([]byte, error)

Get retrieves an artifact by its key.

func (*Store) LatestSnapshot

func (s *Store) LatestSnapshot(ctx context.Context, id event.LoopID) (event.Snapshot, bool, error)

LatestSnapshot returns the most recent snapshot for loop id.

func (*Store) List

List returns loop metadata matching the filter.

func (*Store) Load

func (s *Store) Load(ctx context.Context, id event.LoopID, fromSeq uint64) iter.Seq2[event.Envelope, error]

Load returns an iterator over events for loop id starting at fromSeq.

func (*Store) Put

func (s *Store) Put(ctx context.Context, loopID event.LoopID, seq uint64, data []byte) (string, error)

Put stores data in the artifacts table and returns a key of the form "<loopID>/<seq>". Keys are unique per (loop_id, seq) pair — callers must ensure uniqueness or use a counter suffix when multiple artifacts per seq are possible.

func (*Store) SaveSnapshot

func (s *Store) SaveSnapshot(ctx context.Context, snap event.Snapshot) error

SaveSnapshot persists a snapshot.

Jump to

Keyboard shortcuts

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