driver

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package driver defines the contract every database adapter implements, and a process-wide registry for looking them up by name.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func List

func List() []string

List returns the names of all registered drivers. Order is unspecified.

func Register

func Register(d Driver)

Register adds d to the process-wide registry. Drivers call Register from package init() so they are available before any verb runs.

Register panics if called twice for the same driver name. This mirrors the convention used by database/sql.Register: registration is an init() concern, and a duplicate almost always indicates a copy-paste bug we want to surface loudly at startup rather than have silently overwrite.

Types

type BackupOpts

type BackupOpts struct {
	IncludeTables    []string
	ExcludeTables    []string
	ExcludeDataFrom  []string
	SchemaOnly       bool
	DataOnly         bool
	CompressionLevel int
	Parallel         int
}

BackupOpts configures Conn.Backup.

type BasePositioner

type BasePositioner interface {
	CurrentPosition(ctx context.Context) (canonical.Position, error)
}

BasePositioner reports the engine's current change-stream position, captured during a full backup so a later incremental knows where to resume from.

app.Backup calls this immediately after a full backup completes and stamps the result into the base dump's Envelope. basePosition() then reads a real position instead of the zero value, so the first incremental off a full base resumes from base-end rather than silently starting at "now" (which would drop every change committed between the base dump and the first incremental run).

type CanonicalTransfer

type CanonicalTransfer interface {
	EmitCanonical(ctx context.Context, schema *canonical.CanonicalSchema, w io.Writer) error
	ConsumeCanonical(ctx context.Context, r io.Reader) error
	ApplyChange(ctx context.Context, ch canonical.CanonicalChange) error
}

CanonicalTransfer is an optional interface a Conn may implement to support cross-engine data transfer via the canonical JSONL format.

type Capabilities

type Capabilities struct {
	Incremental             bool
	NativeStream            bool
	PerTable                bool
	SchemaOnly              bool
	DataOnly                bool
	Parallel                bool
	Compression             bool
	BinaryFormat            bool
	CrossEngineSource       bool
	CrossEngineTarget       bool
	CDC                     bool
	NativeBackpressure      bool
	CrossVersionIncremental bool
}

Capabilities describes what an engine supports. Each flag gates a UI affordance or feature path. Drivers must declare honestly.

type ChangeStreamer

type ChangeStreamer interface {
	StreamChanges(ctx context.Context, from canonical.Position, emit func(canonical.CanonicalChange) error) (canonical.Position, error)
}

ChangeStreamer is an optional Conn capability: stream logical row changes as engine-neutral CanonicalChanges, starting after `from`. Bounded callers cancel ctx at a target end position; unbounded (CDC) callers stream until ctx cancel. Returns the final Position reached (for envelope stamping / CDC state persistence).

type Conn

type Conn interface {
	Inspect(ctx context.Context) (*Schema, error)
	Backup(ctx context.Context, opt BackupOpts, w io.Writer) error
	Restore(ctx context.Context, opt RestoreOpts, r io.Reader) error
	Verify(ctx context.Context, r io.Reader) (*VerifyReport, error)
	Close() error
}

Conn is an open connection plus the verbs that operate on it. Conn is the unit of cancellation: ctx propagates to spawned subprocesses.

type Driver

type Driver interface {
	Name() string
	Capabilities() Capabilities
	Connect(ctx context.Context, p Profile) (Conn, error)
}

Driver is the protocol-level abstraction for a database engine. Every adapter (postgres, mysql, mariadb, ...) implements Driver.

Drivers are stateless. Connection state lives in Conn, scoped per-verb.

func Get

func Get(name string) (Driver, error)

Get returns the registered driver with the given name. If no driver matches, it returns errs.ErrDriverUnsupported so callers can match via errors.Is and surface a consistent exit code.

type IncrementalBackuper

type IncrementalBackuper interface {
	BackupIncremental(ctx context.Context, since canonical.Position, w io.Writer) (canonical.Position, error)
}

IncrementalBackuper is an optional Conn capability: capture the BOUNDED change set from `since` to the engine's current end position, serializing each CanonicalChange to w as JSONL, and return the end Position reached.

"Bounded" means the capture stops at a fixed end position captured at the start of the call (Postgres: pg_current_wal_lsn(); MySQL/MariaDB: the current binlog file+offset), unlike CDC's unbounded StreamChanges. It is implemented in terms of StreamChanges' decode machinery with that end position as a stop target. The returned Position is stamped into the incremental dump's Envelope so the NEXT incremental resumes from exactly here.

type Profile

type Profile struct {
	Name     string
	Driver   string
	Host     string
	Port     int
	User     string
	Password string
	Database string
	SSLMode  string
}

Profile is the connection descriptor passed to Connect. Secrets are resolved before this struct reaches Connect; never wire a SecretRef here.

type RestoreOpts

type RestoreOpts struct {
	TargetTables []string
	DataOnly     bool
	SchemaOnly   bool
	Clean        bool
}

RestoreOpts configures Conn.Restore.

type Schema

type Schema struct {
	Tables []TableMeta
}

Schema is the result of Conn.Inspect.

type SchemaInspector

type SchemaInspector interface {
	InspectSchema(ctx context.Context) (*canonical.CanonicalSchema, error)
}

SchemaInspector is an optional interface a Conn may implement to expose typed schema information for cross-engine transfers.

type TableMeta

type TableMeta struct {
	Name      string
	Rows      int64
	SizeBytes int64
}

type VerifyReport

type VerifyReport struct {
	Checksum string
	OK       bool
	Started  time.Time
	Finished time.Time
}

VerifyReport is the result of Conn.Verify.

Directories

Path Synopsis
Package mysqlcommon holds the shared implementation between the MySQL and MariaDB drivers (forks with near-identical tooling).
Package mysqlcommon holds the shared implementation between the MySQL and MariaDB drivers (forks with near-identical tooling).
Package drivertesting holds the shared driver test harness.
Package drivertesting holds the shared driver test harness.
Package mariadb implements siphon's MariaDB driver.
Package mariadb implements siphon's MariaDB driver.
Package mysql implements siphon's MySQL driver.
Package mysql implements siphon's MySQL driver.
Package postgres implements siphon's Postgres driver.
Package postgres implements siphon's Postgres driver.

Jump to

Keyboard shortcuts

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