changeset

package
v0.12.0 Latest Latest
Warning

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

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

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

View Source
const (
	ConflictData       = gosqlite.ConflictData
	ConflictNotFound   = gosqlite.ConflictNotFound
	ConflictConflict   = gosqlite.ConflictConflict
	ConflictConstraint = gosqlite.ConflictConstraint
	ConflictForeignKey = gosqlite.ConflictForeignKey
)
View Source
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 Apply

func Apply(ctx context.Context, sess liteorm.Session, cs []byte, opts ...ApplyOption) error

Apply applies a changeset to sess's database on a dedicated connection.

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.

func Concat

func Concat(ctx context.Context, sess liteorm.Session, a, b []byte) ([]byte, error)

Concat concatenates two changesets into one, as if the second were recorded immediately after the first.

func Invert

func Invert(ctx context.Context, sess liteorm.Session, cs []byte) ([]byte, error)

Invert reverses a changeset: applying the result undoes the original (an undo log). The session connection is only needed to reach the extension.

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.

Jump to

Keyboard shortcuts

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