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 ¶
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 ¶
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) Events ¶
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.