Documentation
¶
Overview ¶
Package sqlitestream opens a SQLite database with PRAGMAs suitable for Litestream and, when a replica URL is configured via WithReplicaURL, restores the file from the replica if it's missing locally and runs continuous replication in the background.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrExists = errors.New("sqlitestream: file exists")
ErrExists is returned by Restore when the output path already exists and force is false.
var ErrNotReplicating = errors.New("sqlitestream: replication not configured")
ErrNotReplicating is returned when an operation requires a configured replica but replication is off.
var ErrReplicaEmpty = errors.New("sqlitestream: replica is empty — nothing to restore")
ErrReplicaEmpty is returned by Restore when the replica holds no snapshots. Callers can treat this as a fresh install.
Functions ¶
func Restore ¶
Restore is a one-shot restore from the replica (configured via WithReplicaURL) into outputPath. It refuses to overwrite an existing file unless force is true; with force the .db, .db-wal and .db-shm files are removed first to give SQLite a clean slate. Used by ops scripts and the `firehose restore` subcommand.
Types ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB is an open SQLite database, optionally with background Litestream replication.
Use SQL to access the underlying *sql.DB; call Close when done — Close flushes the final WAL segment to S3 if replication is on.
func Open ¶
Open opens path with PRAGMAs suitable for Litestream. If WithReplicaURL is supplied, the database is restored from the replica when missing locally and background replication is started before the SQL handle is opened.
func (*DB) Close ¶
Close flushes any pending WAL to S3 (when replication is on), stops the replicator, and closes the SQL handle.
Pass a fresh context — the daemon's main context is typically already cancelled by shutdown time, and a cancelled context aborts the flush.
func (*DB) LastSyncedAt ¶ added in v0.2.0
LastSyncedAt returns the time of the last successful sync to the replica. The zero time means replication is off or nothing has been synced yet.
func (*DB) Replicating ¶ added in v0.2.0
Replicating reports whether background replication is configured.
func (*DB) SyncStatus ¶ added in v0.2.0
func (d *DB) SyncStatus(ctx context.Context) (litestream.SyncStatus, error)
SyncStatus reports the status between the local database and the configured (cloud) storage by comparing transaction records. This may entail I/O. Returns ErrNotReplicating when no replica is configured.
type Option ¶
type Option func(*config)
Option configures Open and Restore.
func WithAWSCredentials ¶
WithCredentials sets credentials separately from the URL. Preferred over embedding "key:secret@" in the URL because URLs are easy to log or expose via process listings.
func WithLogger ¶
WithLogger sets the slog.Logger used for replication and restore events.
func WithReplicaURL ¶
WithReplicaURL configures the Litestream replica destination as a URL, e.g. "s3://bucket/path?region=us-east-1" or "file:///var/lib/replica". Empty disables replication entirely.