sqlite

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package sqlite provides the SQLite dialect.

Importing it registers the dialect under "sqlite" and "sqlite3":

import _ "github.com/gruberchris/rung/dialect/sqlite"

SQLite is not a server, which changes what a "DSN" means and what a migration has to defend against. There is no network, no account, and no other database on the same host to be confused with: a DSN is a file path, or ":memory:", or a file: URI. What it does have that the others do not is a single-writer model, which is why this dialect caps the pool at one connection rather than leaving it to the caller.

The driver is modernc.org/sqlite, which is a pure-Go translation of SQLite rather than a cgo binding. rung publishes a cross-compiled CLI; a cgo driver would make that need a C toolchain per target, and would break the static binary. It is also what keeps `CGO_ENABLED=0 go build` working for anyone embedding rung.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoPath = errors.New("sqlite: the DSN is empty; want a file path, \":memory:\", or a file: URI")

ErrNoPath reports an empty DSN.

Functions

This section is empty.

Types

type Dialect

type Dialect struct{}

Dialect implements rung.Dialect for SQLite 3.

func (Dialect) DropTablesStatement

func (Dialect) DropTablesStatement(quoted []string) string

DropTablesStatement drops every named table.

One DROP per table, because SQLite's DROP TABLE takes exactly one name -- the comma-separated list the other dialects use is a syntax error here. The statement relies on the multi-statement Exec this driver already permits.

Foreign keys are disabled first, so the tables can be dropped in the arbitrary order sqlite_master returns them rather than a computed safe one. They are deliberately not re-enabled afterwards: OFF is SQLite's own default, so leaving it there returns the connection to the state it would have had, whereas switching it ON would impose a setting the caller never asked for.

func (Dialect) LedgerDDL

func (Dialect) LedgerDDL() string

LedgerDDL creates the migration ledger, mirroring the other dialects row for row.

applied_at is declared DATETIME even though SQLite has no date type and stores the value as text. The declared type is not decoration here: the driver reads it to decide how to convert, and a column declared TEXT comes back as a string, so scanning the ledger into a time.Time fails outright with "unsupported Scan". That surfaces on the first status call rather than at migration time, a long way from the CREATE TABLE that caused it.

INTEGER PRIMARY KEY, not AUTOINCREMENT: the column is already a rowid alias and assigns itself. AUTOINCREMENT only adds the monotonicity guarantee nothing here needs, plus an internal sqlite_sequence table.

func (Dialect) LedgerExistsQuery

func (Dialect) LedgerExistsQuery() string

LedgerExistsQuery reports whether the ledger exists.

sqlite_master is per-database by construction, so this needs no equivalent of the TABLE_SCHEMA predicate the server dialects carry: a SQLite connection cannot see another database's tables unless one was deliberately attached.

func (Dialect) ListTablesQuery

func (Dialect) ListTablesQuery() string

ListTablesQuery lists the tables in the database, for rung/reset.

The sqlite_% exclusion is load-bearing rather than tidy. SQLite keeps its own bookkeeping tables in sqlite_master alongside the user's -- sqlite_ sequence appears the moment any table uses AUTOINCREMENT -- and they cannot be dropped: the attempt fails with "table sqlite_sequence may not be dropped" and takes the whole reset with it.

func (Dialect) MigrationsDir

func (Dialect) MigrationsDir() string

MigrationsDir returns "sqlite".

func (Dialect) Name

func (Dialect) Name() string

Name returns the canonical driver name.

func (Dialect) OpenForMigrations

func (Dialect) OpenForMigrations(dsn string) (*sql.DB, error)

OpenForMigrations opens a handle for applying migrations.

Unlike the server dialects, nothing has to be relaxed to permit several statements per Exec: this driver already allows them, and SQLite has no injection-mitigating single-statement mode to turn off.

The pool is capped at one connection. SQLite takes a single writer, so a pool does not buy concurrency -- it converts what database/sql would have queued into SQLITE_BUSY errors raised at the driver, arriving as a failed migration rather than a slow one. Capping it also makes any PRAGMA the caller set in the DSN apply to every statement rung runs, instead of to whichever connection happened to serve it.

An empty DSN is refused rather than passed through. SQLite would accept it and open an anonymous temporary database, so a caller who forgot to configure a path would watch migrations apply successfully to a file that is discarded when the process exits.

func (Dialect) QuoteIdentifier

func (Dialect) QuoteIdentifier(name string) string

QuoteIdentifier quotes a SQL identifier with double quotes.

func (Dialect) Rebind

func (Dialect) Rebind(query string) string

Rebind returns the query unchanged; SQLite already uses ? placeholders.

Jump to

Keyboard shortcuts

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