sqlite

package
v0.5.7 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package sqlite is the meta scale engine: one WAL database, namespace = table group, generic (id, data) rows per root-declared table (§2-§4, v2.28).

Index

Constants

View Source
const (
	// ApplicationID marks a cocoon DB ("COCN"); UserVersion is the schema
	// generation — verified on every open, written only at init (§6).
	ApplicationID = 0x434F434E
	UserVersion   = 1

	// DBFileName is the single database under the meta root; ManifestName
	// beside it marks an in-flight conversion, which ordinary opens refuse (§6).
	DBFileName   = "meta.db"
	ManifestName = "meta-convert.manifest"
)

Variables

This section is empty.

Functions

func Backup

func Backup(ctx context.Context, dbPath, destPath string) error

Backup replaces destPath with a consistent single-file copy: VACUUM INTO a temp file, integrity-check, fsync, atomic rename, parent-dir sync (§4). A previously published backup stays intact until the rename commits (§9).

func Checkpoint

func Checkpoint(ctx context.Context, dbPath string) error

Checkpoint folds the WAL back into the main file (TRUNCATE) so the database is a single self-contained file (§6 aside rule).

func Init

func Init(ctx context.Context, dbPath string, namespaces ...Namespace) error

Init creates a fresh store: schema DDL, identity pragmas and one initialized meta_state row per namespace, all in ONE transaction — a crash mid-init leaves nothing or a complete store (§6). An empty database is a failed init and is restarted; anything else is left for the operator.

func InitForRecovery

func InitForRecovery(ctx context.Context, dbPath string, namespaces ...Namespace) error

InitForRecovery is Init without the manifest guard — the conversion tool creates its target while the manifest is necessarily present (§6).

func InitForRecoveryIfNeeded added in v0.5.6

func InitForRecoveryIfNeeded(ctx context.Context, dbPath string, namespaces ...Namespace) error

InitForRecoveryIfNeeded creates or repairs the conversion target, passing a completed one through.

func InitIfMissing added in v0.5.6

func InitIfMissing(ctx context.Context, dbPath string, namespaces ...Namespace) error

InitIfMissing bootstraps a fresh store or repairs a crashed one, serializing racing processes behind a transient flock.

func MarkConverted

func MarkConverted(ctx context.Context, dbPath, ns, source, sha256 string, records int) error

MarkConverted records a namespace's conversion provenance in meta_state (§6).

func RefuseManifest

func RefuseManifest(dbPath string) error

RefuseManifest fails when a conversion manifest sits beside dbPath, meaning an offline conversion is unfinished.

Types

type Namespace

type Namespace struct {
	Name   string
	Tables []string
}

Namespace declares one namespace's table set; Tables lists the record tables (satellites included) the SPI may address.

type Store

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

Store is the sqlite engine: writerDurable/writerRelaxed single-conn handles, a bounded reader pool, and a pinned notifier connection (§4). Statements are prepared per handle at Open — the table set is static.

func Open

func Open(dbPath string, namespaces ...Namespace) (*Store, error)

Open verifies identity, version and per-namespace meta_state, then builds the connection set. It never creates or migrates — that is Init's job.

func OpenForRecovery

func OpenForRecovery(dbPath string, namespaces ...Namespace) (*Store, error)

OpenForRecovery is Open without the manifest guard, for the conversion tool itself (§6) — never for ordinary callers.

func (*Store) Close

func (s *Store) Close() error

func (*Store) Events

func (s *Store) Events(ctx context.Context) (<-chan struct{}, func(), error)

Events subscribes to committed-change signals: fsnotify on the DB's parent dir confirmed via data_version on a pinned connection — the counter is only comparable across calls on ONE connection and never moves for that connection's own commits (§7).

func (*Store) Update

func (s *Store) Update(ctx context.Context, sc meta.Scope, mode meta.CommitMode, fn func(meta.Writer) error) error

func (*Store) View

func (s *Store) View(ctx context.Context, nss []string, fn func(meta.Reader) error) error

Jump to

Keyboard shortcuts

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