sqlite

package module
v0.6.0 Latest Latest
Warning

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

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

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

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

func Migrate

func Migrate(ctx context.Context, db *sql.DB) error

Migrate applies Schema to db. It is idempotent (CREATE TABLE IF NOT EXISTS), so repeated calls are safe.

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

func New(ctx context.Context, db *sql.DB, opts ...Option) (*Store, error)

New returns a Store wrapping db. By default New applies Schema (idempotent); pass WithoutMigrate to skip that step.

func (*Store) Load

func (s *Store) Load(ctx context.Context, name string) (uint64, bool, error)

Load implements es.CheckpointStore. Returns (0, false, nil) when no checkpoint has been saved for name.

func (*Store) Names added in v0.3.0

func (s *Store) Names(ctx context.Context) iter.Seq2[string, error]

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

func (s *Store) Reset(ctx context.Context, name string) error

Reset implements es.CheckpointStore.

func (*Store) Save

func (s *Store) Save(ctx context.Context, name string, position uint64) error

Save implements es.CheckpointStore.

Jump to

Keyboard shortcuts

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