sqlite

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package sqlite implements the persistence port interfaces using an embedded SQLite database via zombiezen.com/go/sqlite (pure Go, no CGO). It provides database discovery (walking up from cwd to find .np/), schema management, and all CRUD operations with transactional guarantees.

The Store uses a connection pool (sqlitex.Pool) with per-connection pragma setup for WAL mode, foreign keys, and a busy timeout. Write transactions use BEGIN IMMEDIATE so that lock contention is detected — and retried via the busy handler — at BEGIN rather than mid-transaction.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DiscoverDatabase

func DiscoverDatabase(startDir string) (string, error)

DiscoverDatabase walks up from startDir looking for a .np/ directory. Returns the full path to the database file, or an error if not found.

Permission and sandbox errors are silently ignored per §3.3 — if a directory cannot be read, it is skipped.

func InitDatabaseDir

func InitDatabaseDir(baseDir string) (string, error)

InitDatabaseDir creates the .np/ directory and returns the database path.

func LookupDatabase

func LookupDatabase(dir string) (string, error)

LookupDatabase checks a single directory for a .np/ workspace without walking up to parent directories. Returns the full path to the database file, or an error if the directory does not contain an np workspace. Use this when the caller has specified an explicit workspace directory.

Types

type Store

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

Store provides SQLite-backed persistence for the nitpicking domain.

func Create

func Create(dbPath string) (*Store, error)

Create creates a new SQLite database at dbPath and applies the schema. Intended to be called once during database initialisation ("np init"). Subsequent access should use Open, which skips DDL.

func Open

func Open(dbPath string) (*Store, error)

Open opens an existing SQLite database at dbPath. It does not apply schema DDL — the database must already have been created with Create.

func (*Store) Close

func (s *Store) Close() error

Close releases all pooled connections.

func (*Store) Vacuum

func (s *Store) Vacuum(ctx context.Context) error

Vacuum reclaims disk space and defragments the database file. Must be called outside any transaction — takes a connection from the pool, runs VACUUM, and returns it.

func (*Store) WithReadTransaction

func (s *Store) WithReadTransaction(ctx context.Context, fn func(uow driven.UnitOfWork) error) (err error)

WithReadTransaction executes fn within a deferred (read-only) transaction.

func (*Store) WithTransaction

func (s *Store) WithTransaction(ctx context.Context, fn func(uow driven.UnitOfWork) error) (err error)

WithTransaction executes fn within an IMMEDIATE transaction. IMMEDIATE acquires a write lock at BEGIN so that busy-handler retries happen at a point where no deadlock is possible.

Jump to

Keyboard shortcuts

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