database

package
v2.17.1 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package database is a generated GoMock package.

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 CommitOrRollback

func CommitOrRollback(tx transaction.Transaction, err error, logger log.Logger) errors.TracerError

CommitOrRollback will rollback on an errors.TracerError otherwise commit

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 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 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
}

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
}

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) 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 interface{}, 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 interface{}, 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 interface{}) *gomock.Call

CommitOrRollback indicates an expected call of CommitOrRollback.

func (*MockAPIMockRecorder) Count added in v2.15.0

func (mr *MockAPIMockRecorder) Count(arg0, arg1 interface{}) *gomock.Call

Count indicates an expected call of Count.

func (*MockAPIMockRecorder) CountWhere added in v2.15.0

func (mr *MockAPIMockRecorder) CountWhere(arg0, arg1 interface{}) *gomock.Call

CountWhere indicates an expected call of CountWhere.

func (*MockAPIMockRecorder) Create added in v2.10.0

func (mr *MockAPIMockRecorder) Create(obj interface{}) *gomock.Call

Create indicates an expected call of Create.

func (*MockAPIMockRecorder) Delete added in v2.10.0

func (mr *MockAPIMockRecorder) Delete(obj interface{}) *gomock.Call

Delete indicates an expected call of Delete.

func (*MockAPIMockRecorder) DeleteWhere added in v2.10.0

func (mr *MockAPIMockRecorder) DeleteWhere(obj, condition interface{}) *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 interface{}) *gomock.Call

ListWhere indicates an expected call of ListWhere.

func (*MockAPIMockRecorder) Read added in v2.10.0

func (mr *MockAPIMockRecorder) Read(obj, pk interface{}) *gomock.Call

Read indicates an expected call of Read.

func (*MockAPIMockRecorder) ReadOneWhere added in v2.10.0

func (mr *MockAPIMockRecorder) ReadOneWhere(obj, condition interface{}) *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 interface{}) *gomock.Call

Select indicates an expected call of Select.

func (*MockAPIMockRecorder) Update added in v2.10.0

func (mr *MockAPIMockRecorder) Update(obj interface{}) *gomock.Call

Update indicates an expected call of Update.

func (*MockAPIMockRecorder) UpdateWhere added in v2.10.0

func (mr *MockAPIMockRecorder) UpdateWhere(obj, where interface{}, fields ...interface{}) *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 interface{}, query string, args ...interface{}) 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 interface{}, args ...interface{}) *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
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
Package transaction is a generated GoMock package.
Package transaction is a generated GoMock package.

Jump to

Keyboard shortcuts

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