sqlite

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

Package sqlite is the pure-Go SQLite Repository driver — the lightweight / embedded backend tier (single file or :memory:), sitting between Postgres (production, multi-node) and memory (tests). It uses modernc.org/sqlite (NO cgo) so the embeddable library cross-compiles cleanly.

The driver implements service.Repository over the SQLite data plane (every row scoped by `WHERE project_id = $1`, the backend-agnostic isolation boundary — ADR-0002) and satisfies service.DB with the same no-op graph surface the memory driver uses. The control plane (projects registry beyond the boot default, tenants, domains, governance) is Postgres-only; SQLite targets the single-project embedded tier, so it keeps only a `projects` table to anchor the project_id FK chain and the EnsureDefaultProject boot seed.

Schema lives in migrations/ as a squashed final-state SQL file, applied on New() via golang-migrate's pure-Go sqlite driver. JSONB columns are stored as TEXT; partial/expression indexes are preserved; there is no RLS (that stays Postgres-only defense-in-depth).

Index

Constants

View Source
const DefaultMaxConns = 4

DefaultMaxConns is used when Config.MaxConns is zero. SQLite is a single-writer engine, so a small pool is plenty for the embedded tier.

View Source
const MemoryPath = ":memory:"

MemoryPath is the sentinel Path value selecting an in-memory database.

Variables

This section is empty.

Functions

func New

func New(ctx context.Context, cfg Config) (*sqliteRepository, error)

New opens (or creates) the SQLite database at cfg.Path, applies pending migrations, and returns a project-scoped repository. The returned store implements both service.Repository and service.DB.

For an on-disk path the file is created if missing. For an in-memory database (cfg.Path == ":memory:") the store is bound to a single shared connection so every query sees the same database — a fresh connection to ":memory:" would otherwise get an independent empty database.

Types

type Config

type Config struct {
	Path      string
	MaxConns  int
	ProjectID string
}

Config controls how the SQLite repository opens its database.

Path is either a filesystem path (created if missing) or the literal ":memory:" for an ephemeral in-process database. MaxConns caps the connection pool for on-disk databases; in-memory databases are always pinned to a single connection (see New). ProjectID is the project (storage shard) this instance binds to — every data-plane row carries it and the mandatory `WHERE project_id = $1` predicate is bound here (ADR-0002).

Jump to

Keyboard shortcuts

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