database

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package database opens the SQLite database, applies the embedded, versioned migrations (always after a verified backup) and makes verified online backups (spec 7.6).

Index

Constants

This section is empty.

Variables

View Source
var ErrBackupInvalid = errors.New("database: backup failed integrity check")

ErrBackupInvalid means integrity_check of a new backup failed; the file was deleted.

View Source
var ErrTooNew = errors.New("database: schema is newer than this binary")

ErrTooNew means the database was written by a newer pvmon.

Functions

func Backup

func Backup(ctx context.Context, db *sql.DB, s BackupSettings, now time.Time) (string, error)

Backup writes a verified online backup (VACUUM INTO + integrity_check), copies the secret key next to it and prunes old backups. It returns the backup path.

func LatestVersion

func LatestVersion() int

LatestVersion returns the schema version of this binary.

func List

func List(dir string) ([]string, error)

List returns the backups in dir, newest first.

func Migrate

func Migrate(ctx context.Context, db *sql.DB, backup BackupFunc, now time.Time) error

Migrate brings the schema to LatestVersion. A non-empty database is backed up first; a newer database is refused with ErrTooNew.

func Newest

func Newest(dir string) (time.Time, error)

Newest returns the time of the newest backup, zero without backups.

func Open

func Open(ctx context.Context, path string) (*sql.DB, error)

Open opens path with WAL, foreign keys and a single connection.

func OpenReadOnly

func OpenReadOnly(ctx context.Context, path string) (*sql.DB, error)

OpenReadOnly opens an existing database file read-only (mode=ro), e.g. the solis database of an import; a missing file fails instead of creating one.

func Prune

func Prune(dir string, keep int) error

Prune deletes all but the newest keep backups and their key copies.

func Verify

func Verify(ctx context.Context, path string) error

Verify runs PRAGMA integrity_check on a database file.

func Version

func Version(ctx context.Context, db *sql.DB) (int, error)

Version returns the schema version stored in meta (0 for an empty database).

Types

type BackupFunc

type BackupFunc func(ctx context.Context) error

BackupFunc makes and verifies a backup before a migration of a non-empty database.

type BackupSettings

type BackupSettings struct {
	Dir        string // backup directory
	KeyFile    string // data/secret.key; skipped while it does not exist
	MaxBackups int
}

BackupSettings locates backups and the secret key that belongs to them.

Jump to

Keyboard shortcuts

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