sql

package
v1.3.0-activeset-test3... Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 20, 2023 License: MIT Imports: 20 Imported by: 4

Documentation

Overview

Code generated by MockGen. DO NOT EDIT. Source: ./interface.go

Generated by this command:

mockgen -typed -package=sql -destination=./mocks.go -source=./interface.go

Package sql is a generated GoMock package.

Index

Constants

This section is empty.

Variables

View Source
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

func Vacuum added in v1.1.10

func Vacuum(db Executor) error

Types

type Database

type Database struct {
	// contains filtered or unexported fields
}

Database is an instance of sqlite database.

func InMemory

func InMemory(opts ...Opt) *Database

InMemory database for testing.

func Open

func Open(uri string, opts ...Opt) (*Database, error)

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) Close

func (db *Database) Close() error

Close closes all pooled connections.

func (*Database) Exec

func (db *Database) Exec(query string, encoder Encoder, decoder Decoder) (int, error)

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

func (db *Database) Tx(ctx context.Context) (*Tx, error)

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.

https://www.sqlite.org/lang_transaction.html

func (*Database) TxImmediate

func (db *Database) TxImmediate(ctx context.Context) (*Tx, error)

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.

func (*Database) WithTx

func (db *Database) WithTx(ctx context.Context, exec func(*Tx) error) error

WithTx will pass initialized deferred transaction to exec callback. Will commit only if error is nil.

func (*Database) WithTxImmediate

func (db *Database) WithTxImmediate(ctx context.Context, exec func(*Tx) error) error

WithTxImmediate will pass initialized immediate transaction to exec callback. Will commit only if error is nil.

type Decoder

type Decoder func(*Statement) bool

Decoder for sqlite rows.

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 Executor

type Executor interface {
	Exec(string, Encoder, Decoder) (int, error)
}

Executor is an interface for executing raw statement.

type Migration added in v1.3.0

type Migration interface {
	Apply(db Executor) error
	Rollback() error
	Name() string
	Order() int
}

Migration is interface for migrations provider.

func LocalMigrations added in v1.3.0

func LocalMigrations() ([]Migration, error)

func StateMigrations added in v1.3.0

func StateMigrations() ([]Migration, error)

type MigrationApplyCall added in v1.3.0

type MigrationApplyCall struct {
	*gomock.Call
}

MigrationApplyCall wrap *gomock.Call

func (*MigrationApplyCall) Do added in v1.3.0

Do rewrite *gomock.Call.Do

func (*MigrationApplyCall) DoAndReturn added in v1.3.0

func (c *MigrationApplyCall) DoAndReturn(f func(Executor) error) *MigrationApplyCall

DoAndReturn rewrite *gomock.Call.DoAndReturn

func (*MigrationApplyCall) Return added in v1.3.0

func (c *MigrationApplyCall) Return(arg0 error) *MigrationApplyCall

Return rewrite *gomock.Call.Return

type MigrationNameCall added in v1.3.0

type MigrationNameCall struct {
	*gomock.Call
}

MigrationNameCall wrap *gomock.Call

func (*MigrationNameCall) Do added in v1.3.0

func (c *MigrationNameCall) Do(f func() string) *MigrationNameCall

Do rewrite *gomock.Call.Do

func (*MigrationNameCall) DoAndReturn added in v1.3.0

func (c *MigrationNameCall) DoAndReturn(f func() string) *MigrationNameCall

DoAndReturn rewrite *gomock.Call.DoAndReturn

func (*MigrationNameCall) Return added in v1.3.0

func (c *MigrationNameCall) Return(arg0 string) *MigrationNameCall

Return rewrite *gomock.Call.Return

type MigrationOrderCall added in v1.3.0

type MigrationOrderCall struct {
	*gomock.Call
}

MigrationOrderCall wrap *gomock.Call

func (*MigrationOrderCall) Do added in v1.3.0

func (c *MigrationOrderCall) Do(f func() int) *MigrationOrderCall

Do rewrite *gomock.Call.Do

func (*MigrationOrderCall) DoAndReturn added in v1.3.0

func (c *MigrationOrderCall) DoAndReturn(f func() int) *MigrationOrderCall

DoAndReturn rewrite *gomock.Call.DoAndReturn

func (*MigrationOrderCall) Return added in v1.3.0

func (c *MigrationOrderCall) Return(arg0 int) *MigrationOrderCall

Return rewrite *gomock.Call.Return

type MigrationRollbackCall added in v1.3.0

type MigrationRollbackCall struct {
	*gomock.Call
}

MigrationRollbackCall wrap *gomock.Call

func (*MigrationRollbackCall) Do added in v1.3.0

Do rewrite *gomock.Call.Do

func (*MigrationRollbackCall) DoAndReturn added in v1.3.0

func (c *MigrationRollbackCall) DoAndReturn(f func() error) *MigrationRollbackCall

DoAndReturn rewrite *gomock.Call.DoAndReturn

func (*MigrationRollbackCall) Return added in v1.3.0

Return rewrite *gomock.Call.Return

type MockMigration added in v1.3.0

type MockMigration struct {
	// contains filtered or unexported fields
}

MockMigration is a mock of Migration interface.

func NewMockMigration added in v1.3.0

func NewMockMigration(ctrl *gomock.Controller) *MockMigration

NewMockMigration creates a new mock instance.

func (*MockMigration) Apply added in v1.3.0

func (m *MockMigration) Apply(db Executor) error

Apply mocks base method.

func (*MockMigration) EXPECT added in v1.3.0

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockMigration) Name added in v1.3.0

func (m *MockMigration) Name() string

Name mocks base method.

func (*MockMigration) Order added in v1.3.0

func (m *MockMigration) Order() int

Order mocks base method.

func (*MockMigration) Rollback added in v1.3.0

func (m *MockMigration) Rollback() error

Rollback mocks base method.

type MockMigrationMockRecorder added in v1.3.0

type MockMigrationMockRecorder struct {
	// contains filtered or unexported fields
}

MockMigrationMockRecorder is the mock recorder for MockMigration.

func (*MockMigrationMockRecorder) Apply added in v1.3.0

Apply indicates an expected call of Apply.

func (*MockMigrationMockRecorder) Name added in v1.3.0

Name indicates an expected call of Name.

func (*MockMigrationMockRecorder) Order added in v1.3.0

Order indicates an expected call of Order.

func (*MockMigrationMockRecorder) Rollback added in v1.3.0

Rollback indicates an expected call of Rollback.

type Opt

type Opt func(c *conf)

Opt for configuring database.

func WithConnections

func WithConnections(n int) Opt

WithConnections overwrites number of pooled connections.

func WithLatencyMetering

func WithLatencyMetering(enable bool) Opt

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 WithMigration added in v1.3.0

func WithMigration(migration Migration) Opt

WithMigration adds migration to the list of migrations. It will overwrite an existing migration with the same order.

func WithMigrations

func WithMigrations(migrations []Migration) Opt

WithMigrations overwrites embedded migrations. Migrations are sorted by order before applying.

func WithV5Migration added in v1.1.10

func WithV5Migration(cb func(Executor) error) Opt

type Statement

type Statement = sqlite.Stmt

Statement is an sqlite statement.

type Tx

type Tx struct {
	// contains filtered or unexported fields
}

Tx is wrapper for database transaction.

func (*Tx) Commit

func (tx *Tx) Commit() error

Commit transaction.

func (*Tx) Exec

func (tx *Tx) Exec(query string, encoder Encoder, decoder Decoder) (int, error)

Exec query.

func (*Tx) Release

func (tx *Tx) Release() error

Release transaction. Every transaction that was created must be released.

Directories

Path Synopsis
Code generated by MockGen.
Code generated by MockGen.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL