Documentation
¶
Overview ¶
Package sqlite provides the SQLite dialect for Orjanda's DAL. Uses modernc.org/sqlite (pure-Go, no CGo). See TAD §2.3 and PRD §13.3.
Index ¶
- type DB
- func (d *DB) Close() error
- func (d *DB) CreateTables(docs []*schema.CompiledDoc) error
- func (d *DB) Delete(ctx context.Context, docType, id string) error
- func (d *DB) Dialect() dal.Dialect
- func (d *DB) ExistingColumns(tableName string) (map[string]string, error)
- func (d *DB) ExistingTables() (map[string]bool, error)
- func (d *DB) Insert(ctx context.Context, docType string, data map[string]any) (string, error)
- func (d *DB) Query(ctx context.Context, q dal.Select) ([]map[string]any, error)
- func (d *DB) RegisterDoc(docType, tableName string)
- func (d *DB) RegisterDocs(docs []*schema.CompiledDoc)
- func (d *DB) Transaction(ctx context.Context, fn func(dal.Tx) error) error
- func (d *DB) Underlying() *sql.DB
- func (d *DB) Update(ctx context.Context, docType, id string, data map[string]any) error
- type Dialect
- func (d *Dialect) AlterTable(diff schema.TableAlteration) []string
- func (d *Dialect) ColumnType(f schema.Field) string
- func (d *Dialect) CreateTable(doc schema.CompiledDoc) string
- func (d *Dialect) DeleteSQL(tableName, id string) (string, []any)
- func (d *Dialect) DriverName() string
- func (d *Dialect) FullTextSearch(tableName, query string, searchableFields []string) (string, []any)
- func (d *Dialect) InsertSQL(tableName string, fields map[string]any) (string, []any)
- func (d *Dialect) Name() string
- func (d *Dialect) NormalizeColumnType(raw string) string
- func (d *Dialect) Placeholder(_ int) string
- func (d *Dialect) Quote(s string) string
- func (d *Dialect) SelectSQL(q dal.Select) (string, []any)
- func (d *Dialect) UpdateSQL(tableName, id string, fields map[string]any) (string, []any)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB wraps *sql.DB and implements dal.Database for SQLite.
func Open ¶
Open opens a SQLite database at the given DSN (file path or ":memory:").
Pragmas are configured per-connection via modernc shorthand DSN keys, not ExecContext: an ExecContext PRAGMA only touches the single pooled connection that executes it, leaving every later connection (and therefore concurrent writers) unconfigured.
- _journal_mode=WAL: concurrent read/write safety.
- _foreign_keys=1: enable foreign-key enforcement.
- _busy_timeout=5000: wait a bounded time for a held write lock instead of failing immediately with SQLITE_BUSY.
- _txlock=immediate: every transaction is BEGIN IMMEDIATE, taking the write lock at transaction start. A deferred transaction that reads first and writes later holds a stale WAL snapshot and fails the upgrade with SQLITE_BUSY_SNAPSHOT, which the busy handler does not retry — the exact failure mode of two serve instances racing the first-run bootstrap (REVIEW-2026-08-12 finding 12).
func (*DB) CreateTables ¶
func (d *DB) CreateTables(docs []*schema.CompiledDoc) error
CreateTables creates all tables for the given compiled docs (idempotent).
func (*DB) ExistingColumns ¶
ExistingColumns returns the live column names of a table mapped to the type each column reports (PRAGMA type strings, as written at CREATE time).
func (*DB) ExistingTables ¶
ExistingTables returns the set of table names currently in the database.
func (*DB) RegisterDoc ¶
RegisterDoc registers a docType→tableName mapping.
func (*DB) RegisterDocs ¶
func (d *DB) RegisterDocs(docs []*schema.CompiledDoc)
RegisterDocs registers mappings from a slice of CompiledDocs, including the parent→child table mappings so child-table writes (e.g. core.UserRole) resolve.
func (*DB) Transaction ¶
Transaction runs fn inside a database transaction.
type Dialect ¶
type Dialect struct{}
Dialect implements dal.Dialect for SQLite.
func (*Dialect) AlterTable ¶
func (d *Dialect) AlterTable(diff schema.TableAlteration) []string
AlterTable generates ALTER TABLE SQL for column additions and drops. Note: SQLite does not support DROP COLUMN in older versions natively, but modern sqlite (3.35.0+) supports ALTER TABLE DROP COLUMN. SQLite has no ALTER COLUMN TYPE; type changes are surfaced as a review comment so the author can write the required table rebuild manually (forward-only, TAD §14.1 step 2).
func (*Dialect) ColumnType ¶
ColumnType returns the DDL type SQLite uses for the given Field.
func (*Dialect) CreateTable ¶
func (d *Dialect) CreateTable(doc schema.CompiledDoc) string
CreateTable generates CREATE TABLE SQL for the given CompiledDoc.
func (*Dialect) FullTextSearch ¶
func (d *Dialect) FullTextSearch(tableName, query string, searchableFields []string) (string, []any)
FullTextSearch renders a full-text search query. For SQLite, uses LIKE %query% across all searchable text columns as a lightweight MVP implementation.
func (*Dialect) NormalizeColumnType ¶
NormalizeColumnType canonicalizes a PRAGMA-reported column type (which for SQLite is the literal type string written at CREATE time) for comparison with ColumnType's output.
func (*Dialect) Placeholder ¶
Placeholder returns "?" for all positions (SQLite positional style).