storage

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package storage owns SQLite open/PRAGMA/migration plumbing and the minimal Tx interface projectors use. Nothing outside this package should import database/sql directly except cmd/* wiring.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Migrate

func Migrate(ctx context.Context, db *sql.DB, fsys fs.FS, label string) error

Migrate applies a caller-provided embed.FS of goose SQL migrations. Exposed so registry can run its own migration set after Open returns. Each label gets its own goose_db_version_<label> table so migration sets don't collide.

func Open

func Open(ctx context.Context, cfg Config) (*sql.DB, error)

Open opens a SQLite database, applies runtime PRAGMAs, and runs eventstore migrations. Registry migrations are applied via Migrate after this returns. Use OpenReadOnly for read-only clients (e.g. CLI) that must not run migrations.

func OpenReadOnly

func OpenReadOnly(ctx context.Context, cfg Config) (*sql.DB, error)

OpenReadOnly opens the SQLite file with PRAGMAs only — no migrations. Safe to call from CLI processes reading a live daemon database concurrently.

Types

type Config

type Config struct {
	Path string // absolute path to .db file; use ":memory:" for tests
}

type Lockfile

type Lockfile struct {
	// contains filtered or unexported fields
}

Lockfile holds an exclusive PID file for the daemon.

func AcquireLockfile

func AcquireLockfile(dataDir string) (*Lockfile, error)

AcquireLockfile writes <dataDir>/gohomed.lock with the current PID. Returns an error if a live process already owns the file.

func (*Lockfile) Release

func (l *Lockfile) Release() error

type Tx

type Tx interface {
	ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
	QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
	QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
}

Tx is the transactional surface projectors work against. *sql.Tx satisfies this interface directly; test fakes can substitute.

Directories

Path Synopsis
Package migrations embeds eventstore SQL migrations for goose.
Package migrations embeds eventstore SQL migrations for goose.

Jump to

Keyboard shortcuts

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