Documentation ¶
Overview ¶
Package sql is a generated GoMock package.
Index ¶
- Variables
- func AppendToCachedSlice[T any](db any, key queryCacheKey, v T)
- func GetBlobSizes(db Executor, cmd string, ids [][]byte) (sizes []int, err error)
- func IsCached(db any) bool
- func IsNull(stmt *Statement, col int) bool
- func LoadBlob(db Executor, cmd string, id []byte, blob *Blob) error
- func QueryCacheKey(kind QueryCacheKind, key string) queryCacheKey
- func Vacuum(db Executor) error
- func Version(uri string) (int, error)
- func WithCachedSubKey[T any](ctx context.Context, db any, key queryCacheKey, subKey QueryCacheSubKey, ...) (T, error)
- func WithCachedValue[T any](ctx context.Context, db any, key queryCacheKey, ...) (T, error)
- type Blob
- type Database
- func (c Database) ClearCache()
- func (db *Database) Close() error
- func (db *Database) Exec(query string, encoder Encoder, decoder Decoder) (int, error)
- func (c Database) GetValue(ctx context.Context, key queryCacheKey, subKey QueryCacheSubKey, ...) (any, error)
- func (c Database) IsCached() bool
- func (db *Database) QueryCache() QueryCache
- func (db *Database) QueryCount() int
- func (db *Database) Tx(ctx context.Context) (*Tx, error)
- func (db *Database) TxImmediate(ctx context.Context) (*Tx, error)
- func (c Database) UpdateSlice(key queryCacheKey, update SliceAppender)
- 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 Migration
- type MockMigration
- type MockMigrationApplyCall
- type MockMigrationMockRecorder
- type MockMigrationNameCall
- type MockMigrationOrderCall
- type MockMigrationRollbackCall
- type Opt
- func WithConnections(n int) Opt
- func WithLatencyMetering(enable bool) Opt
- func WithLogger(logger *zap.Logger) Opt
- func WithMigration(migration Migration) Opt
- func WithMigrations(migrations []Migration) Opt
- func WithQueryCache(enable bool) Opt
- func WithQueryCacheSizes(sizes map[QueryCacheKind]int) Opt
- func WithSkipMigrations(i ...int) Opt
- func WithVacuumState(i int) Opt
- type QueryCache
- type QueryCacheKind
- type QueryCacheSubKey
- type RetrieveFunc
- type SliceAppender
- type Statement
- type Tx
- func (c Tx) ClearCache()
- func (tx *Tx) Commit() error
- func (tx *Tx) Exec(query string, encoder Encoder, decoder Decoder) (int, error)
- func (c Tx) GetValue(ctx context.Context, key queryCacheKey, subKey QueryCacheSubKey, ...) (any, error)
- func (c Tx) IsCached() bool
- func (tx *Tx) Release() error
- func (c Tx) UpdateSlice(key queryCacheKey, update SliceAppender)
- type UntypedRetrieveFunc
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") // ErrTooNew is returned if database version is newer than expected. ErrTooNew = errors.New("database version is too new") )
Functions ¶
func AppendToCachedSlice ¶ added in v1.4.0
AppendToCachedSlice adds a value to the slice stored in the cache by invoking the specified SliceAppender. If the entry is not cached, the function does nothing.
func GetBlobSizes ¶ added in v1.4.1
GetBlobSizes returns a slice containing the sizes of blobs corresponding to the specified ids. For non-existent ids the corresponding value is -1.
func QueryCacheKey ¶ added in v1.4.0
func QueryCacheKey(kind QueryCacheKind, key string) queryCacheKey
QueryCacheKey creates a key for QueryCache.
func WithCachedSubKey ¶ added in v1.4.0
func WithCachedSubKey[T any]( ctx context.Context, db any, key queryCacheKey, subKey QueryCacheSubKey, retrieve func(ctx context.Context) (T, error), ) (T, error)
WithCachedValue retrieves the specified value identified by the key and subKey from the cache. If the entry is absent from the cache, it's populated by calling retrieve func. Note that the retrieve func should never cause UpdateSlice to be called.
func WithCachedValue ¶ added in v1.4.0
func WithCachedValue[T any]( ctx context.Context, db any, key queryCacheKey, retrieve func(ctx context.Context) (T, error), ) (T, error)
WithCachedValue retrieves the specified value from the cache. If the entry is absent from the cache, it's populated by calling retrieve func. Note that the retrieve func should never cause UpdateSlice to be called.
Types ¶
type Blob ¶ added in v1.4.1
type Blob struct {
Bytes []byte
}
Blob represents a binary blob data. It can be reused efficiently across multiple data retrieval operations, minimizing reallocations of the underlying byte slice.
func (*Blob) FromColumn ¶ added in v1.6.0
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) ClearCache ¶ added in v1.4.0
func (c Database) ClearCache()
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) GetValue ¶ added in v1.4.0
func (c Database) GetValue( ctx context.Context, key queryCacheKey, subKey QueryCacheSubKey, retrieve UntypedRetrieveFunc, ) (any, error)
func (*Database) QueryCache ¶ added in v1.4.0
func (db *Database) QueryCache() QueryCache
Return database's QueryCache.
func (*Database) QueryCount ¶ added in v1.4.0
QueryCount returns the number of queries executed, including failed queries, but not counting transaction start / commit / rollback.
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.
func (Database) UpdateSlice ¶ added in v1.4.0
func (c Database) UpdateSlice(key queryCacheKey, update SliceAppender)
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 Migration ¶ added in v1.3.0
Migration is interface for migrations provider.
func LocalMigrations ¶ added in v1.3.0
func StateMigrations ¶ added in v1.3.0
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
func (m *MockMigration) EXPECT() *MockMigrationMockRecorder
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 MockMigrationApplyCall ¶ added in v1.4.0
MockMigrationApplyCall wrap *gomock.Call
func (*MockMigrationApplyCall) Do ¶ added in v1.4.0
func (c *MockMigrationApplyCall) Do(f func(Executor) error) *MockMigrationApplyCall
Do rewrite *gomock.Call.Do
func (*MockMigrationApplyCall) DoAndReturn ¶ added in v1.4.0
func (c *MockMigrationApplyCall) DoAndReturn(f func(Executor) error) *MockMigrationApplyCall
DoAndReturn rewrite *gomock.Call.DoAndReturn
func (*MockMigrationApplyCall) Return ¶ added in v1.4.0
func (c *MockMigrationApplyCall) Return(arg0 error) *MockMigrationApplyCall
Return rewrite *gomock.Call.Return
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
func (mr *MockMigrationMockRecorder) Apply(db any) *MockMigrationApplyCall
Apply indicates an expected call of Apply.
func (*MockMigrationMockRecorder) Name ¶ added in v1.3.0
func (mr *MockMigrationMockRecorder) Name() *MockMigrationNameCall
Name indicates an expected call of Name.
func (*MockMigrationMockRecorder) Order ¶ added in v1.3.0
func (mr *MockMigrationMockRecorder) Order() *MockMigrationOrderCall
Order indicates an expected call of Order.
func (*MockMigrationMockRecorder) Rollback ¶ added in v1.3.0
func (mr *MockMigrationMockRecorder) Rollback() *MockMigrationRollbackCall
Rollback indicates an expected call of Rollback.
type MockMigrationNameCall ¶ added in v1.4.0
MockMigrationNameCall wrap *gomock.Call
func (*MockMigrationNameCall) Do ¶ added in v1.4.0
func (c *MockMigrationNameCall) Do(f func() string) *MockMigrationNameCall
Do rewrite *gomock.Call.Do
func (*MockMigrationNameCall) DoAndReturn ¶ added in v1.4.0
func (c *MockMigrationNameCall) DoAndReturn(f func() string) *MockMigrationNameCall
DoAndReturn rewrite *gomock.Call.DoAndReturn
func (*MockMigrationNameCall) Return ¶ added in v1.4.0
func (c *MockMigrationNameCall) Return(arg0 string) *MockMigrationNameCall
Return rewrite *gomock.Call.Return
type MockMigrationOrderCall ¶ added in v1.4.0
MockMigrationOrderCall wrap *gomock.Call
func (*MockMigrationOrderCall) Do ¶ added in v1.4.0
func (c *MockMigrationOrderCall) Do(f func() int) *MockMigrationOrderCall
Do rewrite *gomock.Call.Do
func (*MockMigrationOrderCall) DoAndReturn ¶ added in v1.4.0
func (c *MockMigrationOrderCall) DoAndReturn(f func() int) *MockMigrationOrderCall
DoAndReturn rewrite *gomock.Call.DoAndReturn
func (*MockMigrationOrderCall) Return ¶ added in v1.4.0
func (c *MockMigrationOrderCall) Return(arg0 int) *MockMigrationOrderCall
Return rewrite *gomock.Call.Return
type MockMigrationRollbackCall ¶ added in v1.4.0
MockMigrationRollbackCall wrap *gomock.Call
func (*MockMigrationRollbackCall) Do ¶ added in v1.4.0
func (c *MockMigrationRollbackCall) Do(f func() error) *MockMigrationRollbackCall
Do rewrite *gomock.Call.Do
func (*MockMigrationRollbackCall) DoAndReturn ¶ added in v1.4.0
func (c *MockMigrationRollbackCall) DoAndReturn(f func() error) *MockMigrationRollbackCall
DoAndReturn rewrite *gomock.Call.DoAndReturn
func (*MockMigrationRollbackCall) Return ¶ added in v1.4.0
func (c *MockMigrationRollbackCall) Return(arg0 error) *MockMigrationRollbackCall
Return rewrite *gomock.Call.Return
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 WithLogger ¶ added in v1.3.6
func WithMigration ¶ added in v1.3.0
WithMigration adds migration to the list of migrations. It will overwrite an existing migration with the same order.
func WithMigrations ¶
WithMigrations overwrites embedded migrations. Migrations are sorted by order before applying.
func WithQueryCache ¶ added in v1.4.0
WithQueryCache enables in-memory caching of results of some queries.
func WithQueryCacheSizes ¶ added in v1.4.0
func WithQueryCacheSizes(sizes map[QueryCacheKind]int) Opt
WithQueryCacheSizes sets query cache sizes for the specified cache kinds.
func WithSkipMigrations ¶ added in v1.3.0
WithSkipMigrations will update database version with executing associated migrations. It should be used at your own risk.
func WithVacuumState ¶ added in v1.3.0
WithVacuumState will execute vacuum if database version before the migration was less or equal to the provided value.
type QueryCache ¶ added in v1.4.0
type QueryCache interface { // IsCached returns true if the requests are being cached. IsCached() bool // GetValue retrieves the specified key+subKey value from the cache. If // the entry is absent from cache, it's populated by calling retrieve func. // Note that the retrieve func should never cause UpdateSlice to be // called for this cache. GetValue( ctx context.Context, key queryCacheKey, subKey QueryCacheSubKey, retrieve UntypedRetrieveFunc, ) (any, error) // UpdateSlice updates the slice stored in the cache by invoking the // specified SliceAppender. If the entry is not cached, the method does // nothing. UpdateSlice(key queryCacheKey, update SliceAppender) // ClearCache empties the cache. ClearCache() }
QueryCache stores results of SQL queries and data derived from these results. Presently, the cached entries are never removed, but eventually, it might become an LRU cache.
var NullQueryCache QueryCache = (*queryCache)(nil)
type QueryCacheKind ¶ added in v1.4.0
type QueryCacheKind string
type QueryCacheSubKey ¶ added in v1.4.0
type QueryCacheSubKey string
QueryCacheSubKey denotes a cache subkey. The empty subkey refers to the main key. All other subkeys are cleared by UpdateSlice for the key. The subkeys are intended to store data derived from the query results, such as serialized responses.
type RetrieveFunc ¶ added in v1.4.0
RetrieveFunc retrieves a value to be stored in the cache.
type SliceAppender ¶ added in v1.4.0
SliceAppender modifies slice value stored in the cache, appending the specified item to it and returns the updated slice.
type Tx ¶
type Tx struct {
// contains filtered or unexported fields
}
Tx is wrapper for database transaction.
func (Tx) ClearCache ¶ added in v1.4.0
func (c Tx) ClearCache()
func (Tx) GetValue ¶ added in v1.4.0
func (c Tx) GetValue( ctx context.Context, key queryCacheKey, subKey QueryCacheSubKey, retrieve UntypedRetrieveFunc, ) (any, error)
func (Tx) UpdateSlice ¶ added in v1.4.0
func (c Tx) UpdateSlice(key queryCacheKey, update SliceAppender)
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package mocks is a generated GoMock package.
|
Package mocks is a generated GoMock package. |