Documentation
¶
Overview ¶
Package rowsync defines common row storage adapter interfaces and types.
Every durable collection flows through one pipeline: fetch source and destination rows, build one rowsync.Plan with a rowsync.Planner, then apply that plan to a destination. Destinations never recompute changes: they apply Plan.Actions (complete rows in Before/After) and, for PostgreSQL, commit base-table and log changes in one transaction.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Action ¶
type Action[T any] struct { Kind ActionKind Key string Before *T After *T ChangedFields []string }
Action is one deterministic change to apply.
type ActionKind ¶
type ActionKind uint8
ActionKind identifies one planned destination action.
const ( InsertAction ActionKind = iota UpdateAction DeleteAction )
type ActionSummary ¶
type ActionSummary struct {
Kind ActionKind
KeyDigest string
ChangedFields []string
}
ActionSummary is safe for audit output. It never contains the source key.
type AuditRecord ¶
type AuditRecord struct {
Kind ActionKind
KeyDigest string
ChangedFields []string
BeforeDigest string // sha256 of the complete previous row; "" for inserts
AfterDigest string // sha256 of the complete new row; "" for deletes
}
AuditRecord maps one plan action to safe audit metadata: action kind, key digest, changed fields, and digests of the complete old and new rows. Raw row data (which may hold secrets, tokens, or authorization codes) is never exposed; consumers needing full rows hold the plan itself.
type Fetcher ¶
type Fetcher[T any] interface { Init(context.Context) ([]Message, error) Fetch(context.Context) ([]T, error) }
Fetcher reads records from a source.
type InvalidReporter ¶
type InvalidReporter interface {
InvalidCount() int
}
InvalidReporter reports the count of invalid rows in a source.
type InvalidRowReporter ¶
type InvalidRowReporter interface {
InvalidRows() []int
}
InvalidRowReporter reports the row numbers of invalid rows in a source.
type Merge ¶
Merge combines a partial source with existing state. Merged pipelines are insert-update only: destination rows the source lacks survive.
type Plan ¶
Plan is the complete result of comparing source and destination rows.
func (Plan[T]) AuditRecords ¶
func (p Plan[T]) AuditRecords() []AuditRecord
AuditRecords returns one safe audit record per planned action, in plan order. Row digests are stable for value-type rows within a build.
func (Plan[T]) RedactedActions ¶
func (p Plan[T]) RedactedActions() []ActionSummary
RedactedActions returns deterministic action metadata without exposing keys.
type PlanResult ¶
PlanResult contains source rows and the unapplied plan.
type Planner ¶
type Planner[T any] struct { Mode Mode Key func(T) string Equal func(T, T) bool ChangedFields func(T, T) []string }
Planner compares rows by a stable key.
type Result ¶
Result reports the outcome of a fetch → plan → apply run.
func RunMergedStore ¶
func RunMergedStore[T any]( ctx context.Context, input Fetcher[T], output Updater[T], merge Merge[T], planner Planner[T], ) (Result[T], error)
RunMergedStore is RunStore with an explicit merge step for partial sources. The planner is forced to UpdateMode: a partial (merged) source is never authoritative, so destination rows the source lacks survive.
func RunStore ¶
func RunStore[T any]( ctx context.Context, input Fetcher[T], output Updater[T], planner Planner[T], ) (Result[T], error)
RunStore executes the fetch → plan → apply pipeline. The planner's Mode is the explicit operation choice: UpdateMode is insert-update only, SyncMode makes the source authoritative and deletes destination rows the source lacks. An empty source is rejected before planning unless the destination is also empty, in which case the run is a no-op.