Documentation ¶
Overview ¶
Package sqlitepool implements a pool of SQLite database connections.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CopyAll ¶
CopyAll copies the contents of one database to another.
Traditionally this is done in sqlite by closing the database and copying the file. However it can be useful to do it online: a single exclusive transaction can cross multiple databases, and if multiple processes are using a file, this lets one replace the database without first communicating with the other processes, asking them to close the DB first.
The dstSchemaName and srcSchemaName parameters follow the SQLite PRAMGA schema-name conventions: https://sqlite.org/pragma.html#syntax
Types ¶
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
A Pool is a fixed-size pool of SQLite database connections. One is reserved for writable transactions, the others are used for read-only transactions.
func NewPool ¶
func NewPool(filename string, poolSize int, initFn func(sqliteh.DB) error, tracer sqliteh.Tracer) (_ *Pool, err error)
NewPool creates a Pool of poolSize database connections.
For each connection, initFn is called to initialize the connection. Tracer is used to report statistics about the use of the Pool.
func (*Pool) BeginRx ¶
BeginRx creates a read-only transaction. The parameter why is passed to the Tracer for debugging.
type Row ¶
type Row struct {
// contains filtered or unexported fields
}
Row is like database/sql.Tx.Row.
type Rows ¶
type Rows struct {
// contains filtered or unexported fields
}
Rows is like database/sql.Tx.Rows.
type Rx ¶
type Rx struct { // OnRollback is an optional function called after rollback. // If Rx is part of a Tx and it is committed, then OnRollback // is not called. OnRollback func() // contains filtered or unexported fields }
Rx is a read-only transaction.
It is *not* safe for concurrent use.
func (*Rx) DB ¶
DB returns the underlying database connection.
Be careful: a transaction is in progress. Any use of BEGIN/COMMIT/ROLLBACK should be modelled as a nested transaction, and when done the original outer transaction should be left in-progress.
func (*Rx) Prepare ¶
Prepare prepares an SQL statement. The Stmt is cached on the connection, so subsequent calls are fast.
type Tx ¶
type Tx struct { *Rx // OnCommit is an optional function called after successful commit. OnCommit func() }
Tx is a writable SQLite database transaction.
It is *not* safe for concurrent use.
A Tx contains an embedded Rx, which can be used to pass to functions that want to perform read-only queries on the writable Tx.
func (*Tx) Commit ¶
Commit executes COMMIT and cleans up the Tx. It is an error to call if the Tx is already rolled back or committed.