store

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package store owns the SQLite database: opening it with the pragmas a long-running server needs, schema migrations, transactions and the key-value settings table. Every other package runs its own queries through a *DB; none opens the file itself.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound is returned when a looked-up row does not exist.

Functions

This section is empty.

Types

type DB

type DB struct {
	W *sql.DB // the only connection that writes
	R *sql.DB // read-only connections
}

DB is the database, split into one writer connection and a small pool of readers. SQLite allows one writer at a time anyway; giving it a dedicated connection keeps writes from queueing behind busy timeouts, while WAL lets readers proceed concurrently.

func Open

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

Open opens or creates the database at path and migrates it to the current schema.

func (*DB) Backup

func (db *DB) Backup(ctx context.Context, path string) error

Backup writes a consistent copy of the database to path.

func (*DB) Close

func (db *DB) Close() error

Close closes both pools.

func (*DB) DeleteSetting

func (db *DB) DeleteSetting(ctx context.Context, key string) error

DeleteSetting removes one settings value.

func (*DB) SetSetting

func (db *DB) SetSetting(ctx context.Context, key, value string) error

SetSetting writes one settings value.

func (*DB) Setting

func (db *DB) Setting(ctx context.Context, key, def string) (string, error)

Setting reads one settings value; missing keys return def.

func (*DB) Settings

func (db *DB) Settings(ctx context.Context, prefix string) (map[string]string, error)

Settings returns every setting whose key starts with prefix.

func (*DB) Tx

func (db *DB) Tx(ctx context.Context, fn func(*sql.Tx) error) error

Tx runs fn in a write transaction, committing when it returns nil.

Jump to

Keyboard shortcuts

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