sqlite

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package sqlite implements SQLite-specific schema introspection, in-memory shadow validation, and the 12-step table rebuild engine.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AttachDatabases

func AttachDatabases(ctx context.Context, dbtx dialect.DBTX, attach map[string]string) error

AttachDatabases runs ATTACH DATABASE for each schema→path entry on the pinned connection. Names are validated upstream; paths are bound as parameters. "main" must not appear — it is the already-open primary DB.

func AttachMemorySchemas

func AttachMemorySchemas(ctx context.Context, dbtx dialect.DBTX, schemas []string) error

AttachMemorySchemas attaches empty in-memory databases for each schema name other than "main". Used by shadow compilation so desired DDL can target attached schemas without touching live files.

func CompileInShadow

func CompileInShadow(ctx context.Context, schemaSQL string) (*schema.Schema, error)

CompileInShadow executes schemaSQL in an isolated in-memory SQLite database and returns the introspected schema.

func CompileInShadowSchemas

func CompileInShadowSchemas(ctx context.Context, schemaSQL string, schemas []string) (map[string]*schema.Schema, error)

CompileInShadowSchemas compiles schemaSQL against a private :memory: connection with ATTACH ':memory:' AS name for every non-main target schema. Live filesystem paths are never opened — shadow attaches are empty in-memory databases so desired DDL compiles without mutating production files.

func DetachDatabases

func DetachDatabases(ctx context.Context, dbtx dialect.DBTX, names []string) error

DetachDatabases runs DETACH DATABASE for each name (reverse order).

func Diff

func Diff(live, desired *schema.Schema, filters scope.Filters) []plan.Step

Diff compares live and desired schemas and produces a sequenced list of SQLite steps.

func DumpSchema

func DumpSchema(ctx context.Context, dbtx dialect.DBTX, schemaName string) (string, error)

DumpSchema extracts the canonical DDL SQL for all user objects from the SQLite catalog.

func GenerateSQLiteCreateTable

func GenerateSQLiteCreateTable(tbl *schema.Table) string

GenerateSQLiteCreateTable constructs a standard SQLite CREATE TABLE statement.

func GenerateSQLiteRebuildPlan

func GenerateSQLiteRebuildPlan(liveTable, desiredTable *schema.Table, refViews, refTriggers []*schema.UnmanagedObject) (string, bool)

GenerateSQLiteRebuildPlan generates the standard 12-step atomic table replacement plan, preserving and rebinding referencing views and triggers across table recreation.

func Inspect

func Inspect(ctx context.Context, dbtx dialect.DBTX) (*schema.Schema, error)

Inspect extracts the complete relational schema from the primary ("main") SQLite database on the connection.

func InspectSchema

func InspectSchema(ctx context.Context, dbtx dialect.DBTX, schemaName string) (*schema.Schema, error)

InspectSchema extracts the relational schema from a named SQLite schema (e.g. "main" or an ATTACH DATABASE name). Catalog reads use schema.sqlite_schema and PRAGMA schema.table_xinfo.

func InspectSchemas

func InspectSchemas(ctx context.Context, dbtx dialect.DBTX, schemas []string) (map[string]*schema.Schema, error)

InspectSchemas inspects each named schema (including attached databases) and returns a map keyed by schema name.

func NormalizeDefault

func NormalizeDefault(d string) string

NormalizeDefault standardizes default expressions in SQLite.

func NormalizeType

func NormalizeType(t string) string

NormalizeType standardizes SQLite types into canonical representations.

func Render

func Render(step plan.Step) ([]dialect.Stmt, error)

Render implements dialect.Dialect for single steps.

Types

type SQLite

type SQLite struct{}

SQLite implements the dialect.Dialect interface for SQLite.

func New

func New() *SQLite

New returns a new SQLite dialect instance.

func (*SQLite) Introspect

func (s *SQLite) Introspect(ctx context.Context, dbtx dialect.DBTX, targetSchema string) (*schema.Schema, error)

Introspect inspects the SQLite database and returns the schema IR.

func (*SQLite) Name

func (s *SQLite) Name() string

Name returns the dialect identifier "sqlite".

func (*SQLite) Render

func (s *SQLite) Render(step plan.Step) ([]dialect.Stmt, error)

Render translates a migration step into SQLite SQL statements.

Jump to

Keyboard shortcuts

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