database

package
v2.23.1 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Code generated by MockGen. DO NOT EDIT. Source: api.go

Generated by this command:

mockgen -source=api.go -package database -destination api.mock.gen.go

Package database is a generated GoMock package.

Code generated by MockGen. DO NOT EDIT. Source: connection.go

Generated by this command:

mockgen -source=connection.go -package database -destination connection.mock.gen.go

Package database is a generated GoMock package.

Index

Constants

View Source
const (
	// DefaultMaxTries for connecting to the database
	DefaultMaxTries = 10
	// DefaultMaxLimit for row counts on select queries
	DefaultMaxLimit = 100
)
View Source
const (
	// TableExistenceQueryFormat returns a single row and column indicating that the table
	// exists and when it was created. Takes format vars 'table_schema' and 'table_name'
	// NOTE: 'as' clause MUST be there or MySQL will return TABLE_NAME for the column name and
	//  mapping will fail
	// NOTE: Do not use 'create_time' for existence check on tables as it can be NULL
	//  for partitioned tables and is always null in aurora
	TableExistenceQueryFormat = `SELECT TABLE_NAME as "table_name" ` +
		`FROM information_schema.tables` +
		`	WHERE table_schema = '%s'` +
		`	AND table_name = '%s' LIMIT 1;`
)

Variables

View Source
var ErrMissingTransaction = errors.New("missing transaction")

ErrMissingTransaction is returned when a call requiring a transaction is made prior to Begin being called.

Functions

func SelectWithTotal added in v2.16.8

func SelectWithTotal[T any](db API, table qb.Table, target T,
	query *qb.SelectQuery, limit, offset int) (T, int, error)

SelectWithTotal executes the select query populating target and returning the total records possible

func TableExists

func TableExists(db Client, schema, name string) (bool, error)

TableExists for the passed schema and table name on the passed database

Types

type API added in v2.10.0

type API interface {
	// Begin starts a transaction
	Begin() errors.TracerError
	// GetTransaction that is currently on this instance, Begin must be called first.
	GetTransaction() transaction.Transaction
	// Commit commits the transaction
	Commit() errors.TracerError
	// Rollback aborts the transaction
	Rollback() errors.TracerError
	// CommitOrRollback will rollback on an errors.TracerError otherwise commit
	CommitOrRollback(err error) errors.TracerError

	// Count the number of rows in the passed query
	Count(qb.Table, *qb.SelectQuery) (int32, error)
	// CountWhere rows match the passed condition in the specified table. Condition
	// may be nil in order to just count the table rows.
	CountWhere(qb.Table, *qb.ConditionExpression) (int32, error)
	// Create initializes a Record and inserts it into the Database
	Create(obj record.Record) errors.TracerError
	// Read populates a Record from the database
	Read(obj record.Record, pk record.PrimaryKeyValue) errors.TracerError
	// ReadOneWhere populates a Record from a custom where clause
	ReadOneWhere(obj record.Record, condition *qb.ConditionExpression) errors.TracerError
	// Select executes a given select query and populates the target
	Select(target interface{}, query *qb.SelectQuery, options *record.ListOptions) errors.TracerError
	// ListWhere populates target with a list of records from the database
	ListWhere(meta record.Record, target interface{},
		condition *qb.ConditionExpression, options *record.ListOptions) errors.TracerError
	// Update replaces an entry in the database for the Record using a transaction
	Update(obj record.Record) errors.TracerError
	// UpdateWhere updates fields for the Record based on a supplied where clause
	UpdateWhere(obj record.Record, where *qb.ConditionExpression,
		fields ...qb.FieldValue) (int64, errors.TracerError)
	// Delete removes a row from the database
	Delete(obj record.Record) errors.TracerError
	// DeleteWhere removes row(s) from the database based on a supplied where
	// clause in a transaction
	DeleteWhere(obj record.Record, condition *qb.ConditionExpression) errors.TracerError
}

API is a database interface

type BulkCreate added in v2.18.5

type BulkCreate[T record.Record] interface {
	CommitRollbackReset
	// Create initializes the passed Records and buffers them pending
	// the call to commit
	Create(objs ...T)
}

BulkCreate allows for bulk creation of a single resource within a transaction.

func NewBulkCreate added in v2.18.5

func NewBulkCreate[T record.Record](c Connection) (BulkCreate[T], error)

NewBulkCreate API creating multiple records at the same time.

func NewBulkInsert added in v2.21.2

func NewBulkInsert[T record.Record](c Connection, upsert bool) (BulkCreate[T], error)

NewBulkInsert API of BulkCreate with an option to upsert the records.

type BulkUpdate added in v2.18.5

type BulkUpdate[T record.Record] interface {
	CommitRollbackReset
	// Update buffers the update statements until commit is
	// called on this instance.
	Update(objs ...T)
}

BulkUpdate allows for bulk updating of a single resource within a transaction.

func NewBulkUpdate added in v2.18.5

func NewBulkUpdate[T record.Record](
	c Connection,
	columns ...qb.TableField,
) (BulkUpdate[T], error)

NewBulkUpdate of the columns on type T. Only the specified columns will be updated on commit.

type Client added in v2.15.0

type Client interface {
	// necessary for executing non-computed queries
	Select(dest interface{}, query string, args ...interface{}) error
	// Beginx starts a sqlx.Tx and returns it
	Beginx() (*sqlx.Tx, error)
	// Close this client
	Close() error
}

Client interface for working with the database driver functions

type CommitRollbackReset added in v2.18.5

type CommitRollbackReset interface {
	// Reset the pending records and transaction on this instance
	Reset() errors.TracerError
	// Commit the bulk operation to the database
	Commit() (sql.Result, errors.TracerError)
	// Rollback the bulk operation and close the transaction
	Rollback() errors.TracerError
}

CommitRollbackReset is the base interface for Bulk operation clients

type Configuration added in v2.15.0

type Configuration interface {
	// Logger for use with databases configured by this instance
	Logger() log.Logger
	// DatabaseDialect of SQL
	DatabaseDialect() string
	// DatabaseConnection string for addressing the database
	DatabaseConnection() string
	// NumberOfRetries for the connection before failing
	NumberOfRetries() int
	// WaitBetweenRetries before trying again
	WaitBetweenRetries() time.Duration
	// MaxQueryLimit for row counts on select queries
	MaxQueryLimit() uint
	// SlowQueryThreshold for logging slow queries
	SlowQueryThreshold() time.Duration
	// LoggedSlowQueries is a map of queries that have been logged as slow
	LoggedSlowQueries() map[string]time.Duration
}

Configuration defines the interface for a specification to establish a database connection

type Connection added in v2.15.0

type Connection interface {
	// GetConfiguration used to create this instance
	GetConfiguration() Configuration
	// Client for working with this connection at the driver level
	Client() Client
	// Database API that this connection is connected to
	Database() API
	// Close this collection, further calls will panic
	Close() error
}

Connection represents a connection to a database

func Connect added in v2.15.0

func Connect(cfg Configuration) (Connection, error)

type InstanceConfig

type InstanceConfig struct {
	// Dialect of this instance
	Dialect string
	// Connection string for this instance
	Connection string
	// ConnectRetries is the number of times to retry connecting
	ConnectRetries int
	// ConnectRetryWait is the time to wait between connection retries
	ConnectRetryWait time.Duration
	// DeltaLockMaxTries is used as the maximum retries when attempting to get a Lock during Delta execution
	DeltaLockMaxTries int
	// DeltaLockMinimumCycle is used as the minimum cycle duration when attempting to get a Lock during Delta execution
	DeltaLockMinimumCycle time.Duration
	// DeltaLockMaxCycle is used as the maximum wait time between executions when attempting to get a Lock during Delta execution
	DeltaLockMaxCycle time.Duration
	// MaxLimit for row counts on select queries
	MaxLimit uint
	// SlowQuery duration establishes the defintion of a slow query for logging
	SlowQuery time.Duration
	// Log for this instance
	Log log.Logger
	// contains filtered or unexported fields
}

InstanceConfig is a simple struct that satisfies the Config interface

func (*InstanceConfig) DatabaseConnection

func (config *InstanceConfig) DatabaseConnection() string

DatabaseConnection string

func (*InstanceConfig) DatabaseDialect

func (config *InstanceConfig) DatabaseDialect() string

DatabaseDialect indicates the type of SQL this database uses

func (*InstanceConfig) LoggedSlowQueries added in v2.18.2

func (config *InstanceConfig) LoggedSlowQueries() map[string]time.Duration

LoggedSlowQueries is a map of queries that have been logged as slow

func (*InstanceConfig) Logger added in v2.15.0

func (config *InstanceConfig) Logger() log.Logger

Logger for use with databases configured by this instance

func (*InstanceConfig) MaxQueryLimit added in v2.6.0

func (config *InstanceConfig) MaxQueryLimit() uint

MaxQueryLimit for row counts on select queries

func (*InstanceConfig) MaxWaitBetweenDeltaLockRetries

func (config *InstanceConfig) MaxWaitBetweenDeltaLockRetries() time.Duration

WaitBetweenRetries when trying to connect to the database

func (*InstanceConfig) MinimumWaitBetweenDeltaLockRetries

func (config *InstanceConfig) MinimumWaitBetweenDeltaLockRetries() time.Duration

MinimumWaitBetweenDeltaLockRetries when trying to connect to the database

func (*InstanceConfig) NumberOfDeltaLockTries

func (config *InstanceConfig) NumberOfDeltaLockTries() int

NumberOfDeltaLockTries on a connection to the database before failing

func (*InstanceConfig) NumberOfRetries

func (config *InstanceConfig) NumberOfRetries() int

NumberOfRetries on a connection to the database before failing

func (*InstanceConfig) SlowQueryThreshold added in v2.15.0

func (config *InstanceConfig) SlowQueryThreshold() time.Duration

SlowQueryThreshold for logging slow queries

func (*InstanceConfig) WaitBetweenRetries

func (config *InstanceConfig) WaitBetweenRetries() time.Duration

WaitBetweenRetries when trying to connect to the database

type MockAPI added in v2.10.0

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

MockAPI is a mock of API interface.

func NewMockAPI added in v2.10.0

func NewMockAPI(ctrl *gomock.Controller) *MockAPI

NewMockAPI creates a new mock instance.

func (*MockAPI) Begin added in v2.10.0

func (m *MockAPI) Begin() errors.TracerError

Begin mocks base method.

func (*MockAPI) Commit added in v2.10.0

func (m *MockAPI) Commit() errors.TracerError

Commit mocks base method.

func (*MockAPI) CommitOrRollback added in v2.10.0

func (m *MockAPI) CommitOrRollback(err error) errors.TracerError

CommitOrRollback mocks base method.

func (*MockAPI) Count added in v2.15.0

func (m *MockAPI) Count(arg0 qb.Table, arg1 *qb.SelectQuery) (int32, error)

Count mocks base method.

func (*MockAPI) CountWhere added in v2.15.0

func (m *MockAPI) CountWhere(arg0 qb.Table, arg1 *qb.ConditionExpression) (int32, error)

CountWhere mocks base method.

func (*MockAPI) Create added in v2.10.0

func (m *MockAPI) Create(obj record.Record) errors.TracerError

Create mocks base method.

func (*MockAPI) Delete added in v2.10.0

func (m *MockAPI) Delete(obj record.Record) errors.TracerError

Delete mocks base method.

func (*MockAPI) DeleteWhere added in v2.10.0

func (m *MockAPI) DeleteWhere(obj record.Record, condition *qb.ConditionExpression) errors.TracerError

DeleteWhere mocks base method.

func (*MockAPI) EXPECT added in v2.10.0

func (m *MockAPI) EXPECT() *MockAPIMockRecorder

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

func (*MockAPI) GetTransaction added in v2.15.0

func (m *MockAPI) GetTransaction() transaction.Transaction

GetTransaction mocks base method.

func (*MockAPI) ListWhere added in v2.10.0

func (m *MockAPI) ListWhere(meta record.Record, target any, condition *qb.ConditionExpression, options *record.ListOptions) errors.TracerError

ListWhere mocks base method.

func (*MockAPI) Read added in v2.10.0

Read mocks base method.

func (*MockAPI) ReadOneWhere added in v2.10.0

func (m *MockAPI) ReadOneWhere(obj record.Record, condition *qb.ConditionExpression) errors.TracerError

ReadOneWhere mocks base method.

func (*MockAPI) Rollback added in v2.10.0

func (m *MockAPI) Rollback() errors.TracerError

Rollback mocks base method.

func (*MockAPI) Select added in v2.10.0

func (m *MockAPI) Select(target any, query *qb.SelectQuery, options *record.ListOptions) errors.TracerError

Select mocks base method.

func (*MockAPI) Update added in v2.10.0

func (m *MockAPI) Update(obj record.Record) errors.TracerError

Update mocks base method.

func (*MockAPI) UpdateWhere added in v2.10.0

func (m *MockAPI) UpdateWhere(obj record.Record, where *qb.ConditionExpression, fields ...qb.FieldValue) (int64, errors.TracerError)

UpdateWhere mocks base method.

type MockAPIMockRecorder added in v2.10.0

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

MockAPIMockRecorder is the mock recorder for MockAPI.

func (*MockAPIMockRecorder) Begin added in v2.10.0

func (mr *MockAPIMockRecorder) Begin() *gomock.Call

Begin indicates an expected call of Begin.

func (*MockAPIMockRecorder) Commit added in v2.10.0

func (mr *MockAPIMockRecorder) Commit() *gomock.Call

Commit indicates an expected call of Commit.

func (*MockAPIMockRecorder) CommitOrRollback added in v2.10.0

func (mr *MockAPIMockRecorder) CommitOrRollback(err any) *gomock.Call

CommitOrRollback indicates an expected call of CommitOrRollback.

func (*MockAPIMockRecorder) Count added in v2.15.0

func (mr *MockAPIMockRecorder) Count(arg0, arg1 any) *gomock.Call

Count indicates an expected call of Count.

func (*MockAPIMockRecorder) CountWhere added in v2.15.0

func (mr *MockAPIMockRecorder) CountWhere(arg0, arg1 any) *gomock.Call

CountWhere indicates an expected call of CountWhere.

func (*MockAPIMockRecorder) Create added in v2.10.0

func (mr *MockAPIMockRecorder) Create(obj any) *gomock.Call

Create indicates an expected call of Create.

func (*MockAPIMockRecorder) Delete added in v2.10.0

func (mr *MockAPIMockRecorder) Delete(obj any) *gomock.Call

Delete indicates an expected call of Delete.

func (*MockAPIMockRecorder) DeleteWhere added in v2.10.0

func (mr *MockAPIMockRecorder) DeleteWhere(obj, condition any) *gomock.Call

DeleteWhere indicates an expected call of DeleteWhere.

func (*MockAPIMockRecorder) GetTransaction added in v2.15.0

func (mr *MockAPIMockRecorder) GetTransaction() *gomock.Call

GetTransaction indicates an expected call of GetTransaction.

func (*MockAPIMockRecorder) ListWhere added in v2.10.0

func (mr *MockAPIMockRecorder) ListWhere(meta, target, condition, options any) *gomock.Call

ListWhere indicates an expected call of ListWhere.

func (*MockAPIMockRecorder) Read added in v2.10.0

func (mr *MockAPIMockRecorder) Read(obj, pk any) *gomock.Call

Read indicates an expected call of Read.

func (*MockAPIMockRecorder) ReadOneWhere added in v2.10.0

func (mr *MockAPIMockRecorder) ReadOneWhere(obj, condition any) *gomock.Call

ReadOneWhere indicates an expected call of ReadOneWhere.

func (*MockAPIMockRecorder) Rollback added in v2.10.0

func (mr *MockAPIMockRecorder) Rollback() *gomock.Call

Rollback indicates an expected call of Rollback.

func (*MockAPIMockRecorder) Select added in v2.10.0

func (mr *MockAPIMockRecorder) Select(target, query, options any) *gomock.Call

Select indicates an expected call of Select.

func (*MockAPIMockRecorder) Update added in v2.10.0

func (mr *MockAPIMockRecorder) Update(obj any) *gomock.Call

Update indicates an expected call of Update.

func (*MockAPIMockRecorder) UpdateWhere added in v2.10.0

func (mr *MockAPIMockRecorder) UpdateWhere(obj, where any, fields ...any) *gomock.Call

UpdateWhere indicates an expected call of UpdateWhere.

type MockClient added in v2.15.0

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

MockClient is a mock of Client interface.

func NewMockClient added in v2.15.0

func NewMockClient(ctrl *gomock.Controller) *MockClient

NewMockClient creates a new mock instance.

func (*MockClient) Beginx added in v2.15.0

func (m *MockClient) Beginx() (*sqlx.Tx, error)

Beginx mocks base method.

func (*MockClient) Close added in v2.15.0

func (m *MockClient) Close() error

Close mocks base method.

func (*MockClient) EXPECT added in v2.15.0

func (m *MockClient) EXPECT() *MockClientMockRecorder

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

func (*MockClient) Select added in v2.15.0

func (m *MockClient) Select(dest any, query string, args ...any) error

Select mocks base method.

type MockClientMockRecorder added in v2.15.0

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

MockClientMockRecorder is the mock recorder for MockClient.

func (*MockClientMockRecorder) Beginx added in v2.15.0

func (mr *MockClientMockRecorder) Beginx() *gomock.Call

Beginx indicates an expected call of Beginx.

func (*MockClientMockRecorder) Close added in v2.15.0

func (mr *MockClientMockRecorder) Close() *gomock.Call

Close indicates an expected call of Close.

func (*MockClientMockRecorder) Select added in v2.15.0

func (mr *MockClientMockRecorder) Select(dest, query any, args ...any) *gomock.Call

Select indicates an expected call of Select.

type MockConnection added in v2.15.0

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

MockConnection is a mock of Connection interface.

func NewMockConnection added in v2.15.0

func NewMockConnection(ctrl *gomock.Controller) *MockConnection

NewMockConnection creates a new mock instance.

func (*MockConnection) Client added in v2.15.0

func (m *MockConnection) Client() Client

Client mocks base method.

func (*MockConnection) Close added in v2.15.0

func (m *MockConnection) Close() error

Close mocks base method.

func (*MockConnection) Database added in v2.15.0

func (m *MockConnection) Database() API

Database mocks base method.

func (*MockConnection) EXPECT added in v2.15.0

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

func (*MockConnection) GetConfiguration added in v2.15.0

func (m *MockConnection) GetConfiguration() Configuration

GetConfiguration mocks base method.

type MockConnectionMockRecorder added in v2.15.0

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

MockConnectionMockRecorder is the mock recorder for MockConnection.

func (*MockConnectionMockRecorder) Client added in v2.15.0

func (mr *MockConnectionMockRecorder) Client() *gomock.Call

Client indicates an expected call of Client.

func (*MockConnectionMockRecorder) Close added in v2.15.0

func (mr *MockConnectionMockRecorder) Close() *gomock.Call

Close indicates an expected call of Close.

func (*MockConnectionMockRecorder) Database added in v2.15.0

func (mr *MockConnectionMockRecorder) Database() *gomock.Call

Database indicates an expected call of Database.

func (*MockConnectionMockRecorder) GetConfiguration added in v2.15.0

func (mr *MockConnectionMockRecorder) GetConfiguration() *gomock.Call

GetConfiguration indicates an expected call of GetConfiguration.

type TableNameResult

type TableNameResult struct {
	// TableName of the table
	TableName string `db:"table_name"`
}

TableNameResult is for holding the result row from the existence query

Directories

Path Synopsis
Code generated by MockGen.
Code generated by MockGen.
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