Documentation
¶
Overview ¶
Package sqlite provides a SQLite-backed es.CheckpointStore for the synapse event sourcing toolkit.
Schema:
checkpoints(name PK, position)
One row per checkpoint name. Save upserts via ON CONFLICT(name) DO UPDATE. Load returns (0, false, nil) for missing names; Reset deletes the row.
The package blank-imports modernc.org/sqlite to register the pure-Go driver. WAL + busy_timeout + _txlock=immediate are strongly recommended for concurrent workloads (see the eventstore/sqlite package doc for the full rationale on _txlock):
db, err := sql.Open("sqlite",
"file:store.db?_pragma=journal_mode(WAL)"+
"&_pragma=busy_timeout(5000)"+
"&_txlock=immediate")
cps, err := sqlite.New(ctx, db)
The checkpoint store may share the same *sql.DB and file with the SQLite event store and snapshot store, which is the common production case: one database to back up, one to restore.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Schema string
Schema is the SQL DDL this Store requires. It is exported so users who manage migrations externally (goose, golang-migrate, atlas, etc.) can feed it to their own tooling. New applies it by default; WithoutMigrate disables that. Migrate applies it explicitly.
Functions ¶
Types ¶
type Option ¶
type Option func(*options)
Option configures New.
func WithoutMigrate ¶
func WithoutMigrate() Option
WithoutMigrate disables the automatic schema migration that New performs by default. Use this when the schema is managed by an external tool or by an explicit call to Migrate.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is a SQLite-backed es.CheckpointStore.
A Store wraps a *sql.DB the caller provides; the caller retains ownership and is responsible for closing the database.
func New ¶
New returns a Store wrapping db. By default New applies Schema (idempotent); pass WithoutMigrate to skip that step.
func (*Store) Load ¶
Load implements es.CheckpointStore. Returns (0, false, nil) when no checkpoint has been saved for name.
func (*Store) Names ¶ added in v0.3.0
Names implements es.CheckpointStore. It SELECTs every checkpoint name in ascending order and yields them through the iterator. Rows are streamed via sql.Rows; closing the iterator early via the caller's break closes the underlying rows.
func (*Store) Reset ¶
Reset implements es.CheckpointStore.