Documentation
¶
Overview ¶
Package sqlite opens SQLite databases with the pure-Go modernc.org/sqlite driver, so CGO_ENABLED=0 builds work, and builds per-test database clones from a migrated template.
Index ¶
Constants ¶
const DefaultTimeFormat = "sqlite"
DefaultTimeFormat is the modernc _time_format Open sets when the DSN has none: "2006-01-02 15:04:05.999999999-07:00", which sorts, matches CURRENT_TIMESTAMP, and is read by SQLite's date and time functions.
const MemoryConns = 4
MemoryConns is how many connections an in-memory database opened with ":memory:" or a shared-cache memory URI may use at once.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DB ¶
DB is a *sql.DB that can describe itself for `fletch ax inspect`.
func Open ¶
Open returns a database for dsn, a file path, a file: URI, or ":memory:". It is OpenWithOptions with no options.
func OpenWithOptions ¶
OpenWithOptions returns a database for dsn, a file path, a file: URI, or ":memory:", with foreign keys on, a 5 second busy timeout, transactions that take the write lock when they begin (BEGIN IMMEDIATE; read-only transactions excepted), times written in SQLite's own layout, and WAL for file databases. Settings already in the DSN are kept.
":memory:" (or "" or "file::memory:") gets a database of its own under a unique shared-cache name, with MemoryConns connections and read_uncommitted on, so a query can run while *sql.Rows are open or while a transaction is open on another connection; such a query sees the transaction's uncommitted rows. A write outside that transaction still waits for it to end. A shared-cache memory URI ("file::memory:?cache=shared" or "file:name?mode=memory&cache=shared") keeps its name and is pooled the same way. Other in-memory DSNs are used as given, with one connection.
A file database does no I/O until first use. An in-memory one holds a connection from Open to Close, since SQLite frees it with its last connection.
func (*DB) Close ¶
Close closes the database. An in-memory database is freed here, so close d, not d.DB.
func (*DB) Describe ¶
func (d *DB) Describe() data.Description
Describe reports the provider and a redacted DSN.
type Option ¶
type Option func(*config)
Option configures OpenWithOptions.
func WithTimeFormat ¶
WithTimeFormat sets the modernc _time_format used to write time.Time values: "sqlite" (the default), "datetime", or "string_no_monotonic". An empty format keeps the driver's own, Go's Time.String. A _time_format or _time_integer_format in the DSN wins over it.
type Template ¶
type Template struct {
// contains filtered or unexported fields
}
Template is a migrated database image that tests clone.
func NewTemplate ¶
NewTemplate migrates a fresh in-memory database with migrations (nil for an empty schema) and keeps its image. Call it once per test package, for example in TestMain.