store

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package store owns phpbotscout's single SQLite database.

Index and state share one database: FTS5 for BM25 retrieval, ordinary tables for everything else — sources, documents, and in later phases the audit trail, escalation links and feedback. One daemon means one writer, so SQLite's headline weakness does not apply, and keeping the index in the same transactional store as the state it cites is worth more than the concurrency nobody needs.

The driver is pure Go. R-OPS-26 permitted cgo with the native driver and named modernc.org/sqlite as a fallback; the fallback ships FTS5 with BM25 and column weighting, so CGO_ENABLED=0 stays and cross-compilation stays free.

Index

Constants

This section is empty.

Variables

View Source
var ErrMigrationsUnordered = errors.New("store: migrations are not in ascending version order")

ErrMigrationsUnordered is returned when migrations are not in ascending version order. Applying 3 before 2 leaves a schema nobody can reason about, so it is refused rather than sorted silently — the ordering is a property of the source, and quietly fixing it hides a mistake worth seeing.

Functions

This section is empty.

Types

type DB

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

DB is the open database.

func Open

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

Open opens the database at path and brings it up to the current schema.

func OpenWith

func OpenWith(ctx context.Context, path string, ms []Migration) (*DB, error)

OpenWith opens the database and applies the given migrations. Exported so the migration machinery can be tested against deliberately broken input, which is the only way to know a failure leaves the schema intact.

func (*DB) Close

func (db *DB) Close() error

Close releases the database.

func (*DB) Conn

func (db *DB) Conn() *sql.DB

Conn exposes the underlying handle.

Deliberately public: the packages that own their own tables write their own SQL, and wrapping every statement in a method here would turn this package into a second query language with none of the first one's tooling.

func (*DB) Version

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

Version reports the highest applied migration version, or zero on a database that has never been migrated.

type Migration

type Migration struct {
	Version int
	SQL     string
}

Migration is one versioned schema change, applied in its own transaction.

Jump to

Keyboard shortcuts

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