Documentation
¶
Overview ¶
Package changeset exposes SQLite's SESSION extension (changesets/patchsets) through liteorm's SQLite backend, for audit logs and one-way replication. A changeset is a compact binary diff of the rows a set of statements touched; it can be captured on one database, inspected, inverted, and applied to another with a Go conflict handler.
It is SQLite-specific and capability-gated: Capture/Apply take a liteorm session opened by liteorm.org/dialect/sqlite. Capture pins a dedicated connection so the recording session and the mutations share one physical connection — the mutations passed to Capture MUST run against the session it hands back, not the original handle.
Index ¶
- Constants
- func Apply(ctx context.Context, sess liteorm.Session, cs []byte, opts ...ApplyOption) error
- func Capture(ctx context.Context, sess liteorm.Session, tables []string, ...) ([]byte, error)
- func Concat(ctx context.Context, sess liteorm.Session, a, b []byte) ([]byte, error)
- func Invert(ctx context.Context, sess liteorm.Session, cs []byte) ([]byte, error)
- type ApplyOption
- type ConflictAction
- type ConflictType
Constants ¶
const ( ConflictData = gosqlite.ConflictData ConflictNotFound = gosqlite.ConflictNotFound ConflictConflict = gosqlite.ConflictConflict ConflictConstraint = gosqlite.ConflictConstraint ConflictForeignKey = gosqlite.ConflictForeignKey )
const ( Omit = gosqlite.ChangesetOmit // skip this change Replace = gosqlite.ChangesetReplace // overwrite the target row Abort = gosqlite.ChangesetAbort // abort the whole apply )
Variables ¶
This section is empty.
Functions ¶
func Capture ¶
func Capture(ctx context.Context, sess liteorm.Session, tables []string, fn func(ctx context.Context, s liteorm.Session) error) ([]byte, error)
Capture records every change fn makes to the listed tables and returns the serialized changeset. Pass no tables to record every table that has a primary key. fn's mutations must run against the session Capture provides (a pinned connection); changes made through any other handle are not recorded.
Types ¶
type ApplyOption ¶
type ApplyOption = gosqlite.ApplyOption
ApplyOption configures Apply (e.g. WithConflictHandler, WithTableFilter).
func WithConflictHandler ¶
func WithConflictHandler(h func(ConflictType) ConflictAction) ApplyOption
WithConflictHandler resolves each conflicting change. With no handler, any conflict aborts the apply.
func WithTableFilter ¶
func WithTableFilter(f func(table string) bool) ApplyOption
WithTableFilter restricts which tables a changeset is applied to.
type ConflictAction ¶
type ConflictAction = gosqlite.ConflictAction
ConflictAction is a conflict handler's verdict for one conflicting change.
type ConflictType ¶
type ConflictType = gosqlite.ConflictType
ConflictType describes why applying a change conflicted with the target.