// Package driver provides a database/sql driver for SQLite.//// Importing package driver registers a [database/sql] driver named "sqlite3".// You may also need to import package embed.//// import _ "github.com/ncruces/go-sqlite3/driver"// import _ "github.com/ncruces/go-sqlite3/embed"//// The data source name for "sqlite3" databases can be a filename or a "file:" [URI].//// # Default transaction mode//// The [TRANSACTION] mode can be specified using "_txlock"://// sql.Open("sqlite3", "file:demo.db?_txlock=immediate")//// Possible values are: "deferred" (the default), "immediate", "exclusive".// Regardless of "_txlock":// - a [linearizable] transaction is always "exclusive";// - a [serializable] transaction is always "immediate";// - a [read-only] transaction is always "deferred".//// # Datatypes In SQLite//// SQLite is dynamically typed.// Columns can mostly hold any value regardless of their declared type.// SQLite supports most [driver.Value] types out of the box,// but bool and [time.Time] require special care.//// Booleans can be stored on any column type and scanned back to a *bool.// However, if scanned to a *any, booleans may either become an// int64, string or bool, depending on the declared type of the column.// If you use BOOLEAN for your column type,// 1 and 0 will always scan as true and false.//// # Working with time//// Time values can similarly be stored on any column type.// The time encoding/decoding format can be specified using "_timefmt"://// sql.Open("sqlite3", "file:demo.db?_timefmt=sqlite")//// Special values are: "auto" (the default), "sqlite", "rfc3339";// - "auto" encodes as RFC 3339 and decodes any [format] supported by SQLite;// - "sqlite" encodes as SQLite and decodes any [format] supported by SQLite;// - "rfc3339" encodes and decodes RFC 3339 only.//// You can also set "_timefmt" to an arbitrary [sqlite3.TimeFormat] or [time.Layout].//// If you encode as RFC 3339 (the default),// consider using the TIME [collating sequence] to produce time-ordered sequences.//// If you encode as RFC 3339 (the default),// time values will scan back to a *time.Time unless your column type is TEXT.// Otherwise, if scanned to a *any, time values may either become an// int64, float64 or string, depending on the time format and declared type of the column.// If you use DATE, TIME, DATETIME, or TIMESTAMP for your column type,// "_timefmt" will be used to decode values.//// To scan values in custom formats, [sqlite3.TimeFormat.Scanner] may be helpful.// To bind values in custom formats, [sqlite3.TimeFormat.Encode] them before binding.//// When using a custom time struct, you'll have to implement// [database/sql/driver.Valuer] and [database/sql.Scanner].//// The Value method should ideally encode to a time [format] supported by SQLite.// This ensures SQL date and time functions work as they should,// and that your schema works with other SQLite tools.// [sqlite3.TimeFormat.Encode] may help.//// The Scan method needs to take into account that the value it receives can be of differing types.// It can already be a [time.Time], if the driver decoded the value according to "_timefmt" rules.// Or it can be a: string, int64, float64, []byte, or nil,// depending on the column type and whoever wrote the value.// [sqlite3.TimeFormat.Decode] may help.//// # Setting PRAGMAs//// [PRAGMA] statements can be specified using "_pragma"://// sql.Open("sqlite3", "file:demo.db?_pragma=busy_timeout(10000)")//// If no PRAGMAs are specified, a busy timeout of 1 minute is set.//// Order matters:// encryption keys, busy timeout and locking mode should be the first PRAGMAs set,// in that order.//// [URI]: https://sqlite.org/uri.html// [PRAGMA]: https://sqlite.org/pragma.html// [TRANSACTION]: https://sqlite.org/lang_transaction.html#deferred_immediate_and_exclusive_transactions// [linearizable]: https://pkg.go.dev/database/sql#TxOptions// [serializable]: https://pkg.go.dev/database/sql#TxOptions// [read-only]: https://pkg.go.dev/database/sql#TxOptions// [format]: https://sqlite.org/lang_datefunc.html#time_values// [collating sequence]: https://sqlite.org/datatype3.html#collating_sequences
The pages are generated with Goldsv0.8.2. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.