Documentation ¶
Index ¶
- Variables
- func Vacuum(db Executor) error
- type Database
- func (db *Database) Close() error
- func (db *Database) Exec(query string, encoder Encoder, decoder Decoder) (int, error)
- func (db *Database) Tx(ctx context.Context) (*Tx, error)
- func (db *Database) TxImmediate(ctx context.Context) (*Tx, error)
- func (db *Database) WithTx(ctx context.Context, exec func(*Tx) error) error
- func (db *Database) WithTxImmediate(ctx context.Context, exec func(*Tx) error) error
- type Decoder
- type Encoder
- type Executor
- type Migrations
- type Opt
- type Statement
- type Tx
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoConnection is returned if pooled connection is not available. ErrNoConnection = errors.New("database: no free connection") // ErrNotFound is returned if requested record is not found. ErrNotFound = errors.New("database: not found") // ErrObjectExists is returned if database constraints didn't allow to insert an object. ErrObjectExists = errors.New("database: object exists") )
Functions ¶
Types ¶
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
Database is an instance of sqlite database.
func Open ¶
Open database with options.
Database is opened in WAL mode and pragma synchronous=normal. https://sqlite.org/wal.html https://www.sqlite.org/pragma.html#pragma_synchronous
func (*Database) Exec ¶
Exec statement using one of the connection from the pool.
If you care about atomicity of the operation (for example writing rewards to multiple accounts) Tx should be used. Otherwise sqlite will not guarantee that all side-effects of operations are applied to the database if machine crashes.
Note that Exec will block until database is closed or statement has finished. If application needs to control statement execution lifetime use one of the transaction.
func (*Database) Tx ¶
Tx creates deferred sqlite transaction.
Deferred transactions are not started until the first statement. Transaction may be started in read mode and automatically upgraded to write mode after one of the write statements.
func (*Database) TxImmediate ¶
TxImmediate creates immediate transaction.
IMMEDIATE cause the database connection to start a new write immediately, without waiting for a write statement. The BEGIN IMMEDIATE might fail with SQLITE_BUSY if another write transaction is already active on another database connection.
type Encoder ¶
type Encoder func(*Statement)
Encoder for parameters. Both positional parameters: select block from blocks where id = ?1;
and named parameters are supported: select blocks from blocks where id = @id;
For complete information see https://www.sqlite.org/c3ref/bind_blob.html.
type Migrations ¶
Migrations is interface for migrations provider.
type Opt ¶
type Opt func(c *conf)
Opt for configuring database.
func WithConnections ¶
WithConnections overwrites number of pooled connections.
func WithLatencyMetering ¶
WithLatencyMetering enables metric that track latency for every database query. Note that it will be a significant amount of data, and should not be enabled on multiple nodes by default.
func WithMigrations ¶
func WithMigrations(migrations Migrations) Opt
WithMigrations overwrites embedded migrations.