Documentation
¶
Overview ¶
Package drivers defines the Config type that sqlflow uses to build connection strings and detect permanent errors for a specific SQLite driver.
Normally you do not use this package directly. Import one of the driver sub-packages instead — they register the underlying SQLite driver and export a ready-to-use sqlflow.Option:
import "github.com/avalonbits/sqlflow/drivers/mattn" db, err := sqlflow.OpenDB(path, querier, mattn.Driver, ...)
The pragma-style DSN helpers (PragmaBuildDSN, PragmaInMemoryDSN) are exported for use by the modernc and ncruces driver sub-packages.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PragmaBuildDSN ¶
PragmaBuildDSN builds a plain file DSN using _pragma=name(value) query parameters. Used by the modernc and ncruces driver sub-packages.
func PragmaInMemoryDSN ¶
func PragmaInMemoryDSN(shared bool, name, txlock string, params url.Values, pragmas [][2]string) string
PragmaInMemoryDSN builds an in-memory DSN for pragma-style drivers. name is the database name in the URI (unique per TestDB call for drivers that require shared-cache). shared adds cache=shared, which is required by modernc for in-memory databases opened across multiple connections.
Types ¶
type Config ¶
type Config struct {
// Name is the driver name as registered with database/sql (e.g. "sqlite3").
Name string
// BuildDSN builds a plain (unencrypted) connection DSN for the given file
// path and transaction lock mode.
BuildDSN func(path, txlock string, params url.Values, pragmas [][2]string) string
// BuildCipherDSN builds an encrypted connection DSN. Nil means the driver
// does not support encryption; sqlflow returns ErrEncryptionNotSupported.
BuildCipherDSN func(path, txlock string, key []byte, params url.Values, pragmas [][2]string) string
// MemoryDSN builds an in-memory DSN for TestDB. name is a unique identifier
// per TestDB call; drivers using shared-cache in-memory databases (modernc)
// must use it to isolate parallel test instances.
MemoryDSN func(name, txlock string, params url.Values, pragmas [][2]string) string
// IsPermanentErr reports whether err is a connection-level error that should
// never be retried (e.g. wrong cipher key, corrupt file).
IsPermanentErr func(error) bool
}
Config holds everything sqlflow needs to open connections for a specific SQLite driver. Construct one in the relevant drivers/* sub-package rather than here.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package mattn registers the github.com/mattn/go-sqlite3 SQLite driver and exports a ready-to-use sqlflow.Option that selects it.
|
Package mattn registers the github.com/mattn/go-sqlite3 SQLite driver and exports a ready-to-use sqlflow.Option that selects it. |
|
Package modernc registers the modernc.org/sqlite SQLite driver (pure Go, no CGo) and exports a ready-to-use sqlflow.Option that selects it.
|
Package modernc registers the modernc.org/sqlite SQLite driver (pure Go, no CGo) and exports a ready-to-use sqlflow.Option that selects it. |
|
Package ncruces registers the github.com/ncruces/go-sqlite3 SQLite driver (WebAssembly, no CGo) and exports a ready-to-use sqlflow.Option that selects it.
|
Package ncruces registers the github.com/ncruces/go-sqlite3 SQLite driver (WebAssembly, no CGo) and exports a ready-to-use sqlflow.Option that selects it. |