Help us shape the future of Go! Take the 2026 Go Developer Survey

sqlitelog

package module
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package sqlitelog is a durable, on-disk govern.EventLog backed by single-file SQLite (zero-cgo). It gives a PersistentGovernor real crash-recovery: events survive a process restart on disk, and (with a shared file / Postgres equivalent) multiple processes read the same governed event stream. It satisfies govern.EventLog structurally, so this package doesn't import govern — keeping the coupling one-directional.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Log

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

Log is an on-disk append-only event log per entity.

func Open

func Open(path string) (*Log, error)

Open opens (creating if needed) an event log at path (":memory:" for ephemeral). It uses the canonical path (absolute, symlinks resolved), so that every handle on the file makes SQLite derive the same -wal and -shm names, and it refuses a file with more than one hard link, which has no canonical name, with an error wrapping agent.ErrConfig: two names for one WAL-mode database corrupt it (https://sqlite.org/howtocorrupt.html).

func (*Log) Append

func (l *Log) Append(ctx context.Context, entity, id, event string) (int64, error)

Append durably records an event for an entity under id and returns its position (its seq). The seq is computed and inserted in one statement; SQLite serializes writers, and the (entity, seq) primary key rejects a duplicate, so concurrent appends from any number of processes get distinct, dense positions. The unique (entity, append_id) index makes the append idempotent: if the entity already holds id, nothing is inserted and the recorded position is returned.

func (*Log) Close

func (l *Log) Close() error

Close releases the underlying database handle.

func (*Log) Events

func (l *Log) Events(ctx context.Context, entity string, from int64) ([]string, error)

Events returns an entity's events at positions from onward, in log order. Positions are dense, so the i-th event read is the one at position from+i; a row whose seq breaks that (a row deleted or renumbered outside this adapter) is an error wrapping agent.ErrProtocol, since the caller would otherwise take a later event for the one at the missing position.

Jump to

Keyboard shortcuts

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