Artifact 3824fba956019dbf5297c119273b9d1b10a48789bc2c8b85680d86f8bfd5addf:
- File
docs/site/content/docs/reference/sdk/db/api.md
— part of check-in
[f30849a466]
at
2026-04-26 14:14:53
on branch trunk
— docs: usability improvements from DX audit (#9)
Implements all seven recommended changes from the docs audit:
1. SDK pages now show package names in nav. Add scripts/prepend-sdk-frontmatter.sh that prepends '--- title: <pkg> ---' to each gomarkdoc-generated api.md; wired into 'make docs-gen-sdk'. Sidebar previously showed five undifferentiated 'API' entries; now shows cli, db, dst, libfossil, observer/otel.
2. /examples/ populated with paragraphs + GitHub deep-links for embed-repo-api and wasm. No longer a placeholder pointing back at the repo.
3. Architecture page gets an inline SVG mirroring the landing-page diagram. Self-contained CSS (uses currentColor + ember accent) so it tracks Hextra's light/dark theme without depending on the landing's CSS scope.
4. Cross-links added: quickstart -> production + extension-points, migration -> architecture, architecture -> extension-points. Extension Points and Production patterns are now reachable via prose, not just the sidebar.
5. /docs/ landing expanded from 3 sentences to a 7-line subsection map calling out each page's purpose.
6. Version indicator in navbar (libfossil v0.4.2). Override layouts/_partials/navbar-title.html mimics Hextra's default and appends a small mono version tag from .Site.Params.version.
7. New /docs/production/ page covering error handling, context cancellation, telemetry wiring, repo-handle lifetime, and driver selection — the patterns the quickstart's log.Fatal shortcuts gloss over. (user: [email protected], size: 9901) [annotate] [blame] [check-ins using]
title: db
<!-- Code generated by gomarkdoc. DO NOT EDIT -->db
import "github.com/danmestas/libfossil/db"
Package db provides a SQLite database layer with pluggable drivers.
Two SQLite drivers ship with libfossil — modernc (pure Go, default) and ncruces (WASM-capable). Select one at build time by importing its driver package:
import _ "github.com/danmestas/libfossil/db/driver/modernc"
Open and OpenWith handle DSN construction, WAL/pragma setup, and WASM-specific workarounds. Use DB.WithTx for transaction scoping with automatic rollback on error.
The Querier interface (Exec, QueryRow, Query) is satisfied by both DB and Tx, allowing callers to write transaction-agnostic code.
Index
- func CreateRepoSchema(d *DB) error
- func DefaultPragmas() map[string]string
- func Register(cfg DriverConfig)
- func ScanInt(v any) (int, bool)
- func ScanJulianDay(v any) (float64, bool)
- func ScanTime(v any) (time.Time, bool)
- func SeedConfig(d *DB, rng simio.Rand) error
- func SeedNobody(d *DB, caps string) error
- func SeedUser(d *DB, login string) error
- type DB
- func Open(path string) (*DB, error)
- func OpenWith(path string, cfg OpenConfig) (*DB, error)
- func (d *DB) ApplicationID() (int32, error)
- func (d *DB) Close() error
- func (d *DB) Driver() string
- func (d *DB) Exec(query string, args ...any) (sql.Result, error)
- func (d *DB) Path() string
- func (d *DB) Query(query string, args ...any) (*sql.Rows, error)
- func (d *DB) QueryRow(query string, args ...any) *sql.Row
- func (d *DB) SetApplicationID(id int32) error
- func (d *DB) SqlDB() *sql.DB
- func (d *DB) WithTx(fn func(tx *Tx) error) error
- type DriverConfig
- type OpenConfig
- type Querier
- type Tx
func CreateRepoSchema
func CreateRepoSchema(d *DB) error
func DefaultPragmas
func DefaultPragmas() map[string]string
DefaultPragmas returns the default pragma settings.
func Register
func Register(cfg DriverConfig)
Register registers a SQLite driver for use by Open/OpenWith. Must be called exactly once (typically from a driver package's init()). Panics if called more than once.
func ScanInt
func ScanInt(v any) (int, bool)
ScanInt converts a scanned value to int. SQLite drivers differ on BOOLEAN columns: modernc returns int64, ncruces returns bool. Scan the column into an `any` variable, then pass it here.
func ScanJulianDay
func ScanJulianDay(v any) (float64, bool)
ScanJulianDay converts a scanned mtime value to a float64 Julian Day Number. SQLite drivers return mtime differently: modernc returns float64, ncruces returns time.Time for DATETIME/TIMESTAMP/DATE columns. Scan the column into an `any` variable, then pass it here.
func ScanTime
func ScanTime(v any) (time.Time, bool)
ScanTime converts a scanned mtime value to time.Time. Same driver-compatibility rationale as ScanJulianDay.
func SeedConfig
func SeedConfig(d *DB, rng simio.Rand) error
func SeedNobody
func SeedNobody(d *DB, caps string) error
SeedNobody inserts a "nobody" user with the given capabilities. This controls anonymous access policy for the repo.
func SeedUser
func SeedUser(d *DB, login string) error
type DB
DB wraps a SQLite database connection.
type DB struct {
// contains filtered or unexported fields
}
func Open
func Open(path string) (*DB, error)
Open opens a SQLite database with the registered driver and default pragmas.
func OpenWith
func OpenWith(path string, cfg OpenConfig) (*DB, error)
OpenWith opens a SQLite database with explicit configuration.
func (*DB) ApplicationID
func (d *DB) ApplicationID() (int32, error)
func (*DB) Close
func (d *DB) Close() error
func (*DB) Driver
func (d *DB) Driver() string
func (*DB) Exec
func (d *DB) Exec(query string, args ...any) (sql.Result, error)
func (*DB) Path
func (d *DB) Path() string
func (*DB) Query
func (d *DB) Query(query string, args ...any) (*sql.Rows, error)
func (*DB) QueryRow
func (d *DB) QueryRow(query string, args ...any) *sql.Row
func (*DB) SetApplicationID
func (d *DB) SetApplicationID(id int32) error
func (*DB) SqlDB
func (d *DB) SqlDB() *sql.DB
SqlDB returns the underlying *sql.DB connection.
func (*DB) WithTx
func (d *DB) WithTx(fn func(tx *Tx) error) error
type DriverConfig
DriverConfig defines a SQLite driver's name and DSN builder.
type DriverConfig struct {
Name string
BuildDSN func(path string, pragmas map[string]string) string
}
func RegisteredDriver
func RegisteredDriver() *DriverConfig
RegisteredDriver returns a copy of the currently registered driver config, or nil if none.
type OpenConfig
OpenConfig allows callers to customize driver selection and pragmas.
type OpenConfig struct {
Driver string // override driver name (empty = use registered driver)
Pragmas map[string]string // additional/override pragmas (merged with defaults)
}
type Querier
Querier is the common interface satisfied by both *DB and *Tx. Functions that need to work inside transactions accept Querier instead of *DB.
type Querier interface {
Exec(query string, args ...any) (sql.Result, error)
QueryRow(query string, args ...any) *sql.Row
Query(query string, args ...any) (*sql.Rows, error)
}
type Tx
type Tx struct {
// contains filtered or unexported fields
}
func (*Tx) Exec
func (t *Tx) Exec(query string, args ...any) (sql.Result, error)
func (*Tx) Query
func (t *Tx) Query(query string, args ...any) (*sql.Rows, error)
func (*Tx) QueryRow
func (t *Tx) QueryRow(query string, args ...any) *sql.Row
Generated by gomarkdoc