database

package
v0.0.0-...-39f3c58 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SuppressNoRowsError

func SuppressNoRowsError(err error) error

SuppressNoRowsError suppresses the sql.ErrNoRows error.

Types

type Database

type Database interface {
	// Exec executes a query. Should be used for write operations.
	// When used inside WithTx, the query is executed within the transaction.
	// If dest is nil, the query is executed without expecting any result.
	// If dest is a pointer to a slice or an array, the query is executed and the result is stored in the slice or array.
	// If dest is a pointer to a struct, the query is executed and the result is stored in the struct.
	Exec(ctx context.Context, dest any, query string, args ...any) error

	// Get executes a query that is expected to return at most one row. Should be used for read operations.
	// When used inside WithTx, the query is executed within the transaction.
	// The result is stored in the dest.
	Get(ctx context.Context, dest any, query string, args ...any) error

	// List executes a query that is expected to return multiple rows. Should be used for read operations.
	// When used inside WithTx, the query is executed within the transaction.
	// The result is stored in the dest.
	List(ctx context.Context, dest any, query string, args ...any) error

	Transactor
}

Database is an interface that defines the methods that a database should implement.

func NewPostgresDatabase

func NewPostgresDatabase(db *sqlx.DB) Database

NewPostgresDatabase creates a new instance of the postgresDatabase. Currently we are executing the queries directly. The idea to use different connections for read and write operations. The Exec method will be used for write operations. Get & Select methods will be used for readonly operations.

type MockDatabase

type MockDatabase struct {
	mock.Mock
}

MockDatabase is an autogenerated mock type for the Database type

func NewMockDatabase

func NewMockDatabase(t interface {
	mock.TestingT
	Cleanup(func())
}) *MockDatabase

NewMockDatabase creates a new instance of MockDatabase. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*MockDatabase) EXPECT

func (_m *MockDatabase) EXPECT() *MockDatabase_Expecter

func (*MockDatabase) Exec

func (_m *MockDatabase) Exec(ctx context.Context, dest interface{}, query string, args ...interface{}) error

Exec provides a mock function with given fields: ctx, dest, query, args

func (*MockDatabase) Get

func (_m *MockDatabase) Get(ctx context.Context, dest interface{}, query string, args ...interface{}) error

Get provides a mock function with given fields: ctx, dest, query, args

func (*MockDatabase) List

func (_m *MockDatabase) List(ctx context.Context, dest interface{}, query string, args ...interface{}) error

List provides a mock function with given fields: ctx, dest, query, args

func (*MockDatabase) WithTx

func (_m *MockDatabase) WithTx(ctx context.Context, txFn func(context.Context) error) error

WithTx provides a mock function with given fields: ctx, txFn

type MockDatabase_Exec_Call

type MockDatabase_Exec_Call struct {
	*mock.Call
}

MockDatabase_Exec_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Exec'

func (*MockDatabase_Exec_Call) Return

func (*MockDatabase_Exec_Call) Run

func (_c *MockDatabase_Exec_Call) Run(run func(ctx context.Context, dest interface{}, query string, args ...interface{})) *MockDatabase_Exec_Call

func (*MockDatabase_Exec_Call) RunAndReturn

func (_c *MockDatabase_Exec_Call) RunAndReturn(run func(context.Context, interface{}, string, ...interface{}) error) *MockDatabase_Exec_Call

type MockDatabase_Expecter

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

func (*MockDatabase_Expecter) Exec

func (_e *MockDatabase_Expecter) Exec(ctx interface{}, dest interface{}, query interface{}, args ...interface{}) *MockDatabase_Exec_Call

Exec is a helper method to define mock.On call

  • ctx context.Context
  • dest interface{}
  • query string
  • args ...interface{}

func (*MockDatabase_Expecter) Get

func (_e *MockDatabase_Expecter) Get(ctx interface{}, dest interface{}, query interface{}, args ...interface{}) *MockDatabase_Get_Call

Get is a helper method to define mock.On call

  • ctx context.Context
  • dest interface{}
  • query string
  • args ...interface{}

func (*MockDatabase_Expecter) List

func (_e *MockDatabase_Expecter) List(ctx interface{}, dest interface{}, query interface{}, args ...interface{}) *MockDatabase_List_Call

List is a helper method to define mock.On call

  • ctx context.Context
  • dest interface{}
  • query string
  • args ...interface{}

func (*MockDatabase_Expecter) WithTx

func (_e *MockDatabase_Expecter) WithTx(ctx interface{}, txFn interface{}) *MockDatabase_WithTx_Call

WithTx is a helper method to define mock.On call

  • ctx context.Context
  • txFn func(context.Context) error

type MockDatabase_Get_Call

type MockDatabase_Get_Call struct {
	*mock.Call
}

MockDatabase_Get_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Get'

func (*MockDatabase_Get_Call) Return

func (*MockDatabase_Get_Call) Run

func (_c *MockDatabase_Get_Call) Run(run func(ctx context.Context, dest interface{}, query string, args ...interface{})) *MockDatabase_Get_Call

func (*MockDatabase_Get_Call) RunAndReturn

func (_c *MockDatabase_Get_Call) RunAndReturn(run func(context.Context, interface{}, string, ...interface{}) error) *MockDatabase_Get_Call

type MockDatabase_List_Call

type MockDatabase_List_Call struct {
	*mock.Call
}

MockDatabase_List_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'List'

func (*MockDatabase_List_Call) Return

func (*MockDatabase_List_Call) Run

func (_c *MockDatabase_List_Call) Run(run func(ctx context.Context, dest interface{}, query string, args ...interface{})) *MockDatabase_List_Call

func (*MockDatabase_List_Call) RunAndReturn

func (_c *MockDatabase_List_Call) RunAndReturn(run func(context.Context, interface{}, string, ...interface{}) error) *MockDatabase_List_Call

type MockDatabase_WithTx_Call

type MockDatabase_WithTx_Call struct {
	*mock.Call
}

MockDatabase_WithTx_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithTx'

func (*MockDatabase_WithTx_Call) Return

func (*MockDatabase_WithTx_Call) Run

func (*MockDatabase_WithTx_Call) RunAndReturn

type MockTransactor

type MockTransactor struct {
	mock.Mock
}

MockTransactor is an autogenerated mock type for the Transactor type

func NewMockTransactor

func NewMockTransactor(t interface {
	mock.TestingT
	Cleanup(func())
}) *MockTransactor

NewMockTransactor creates a new instance of MockTransactor. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*MockTransactor) EXPECT

func (*MockTransactor) WithTx

func (_m *MockTransactor) WithTx(ctx context.Context, txFn func(context.Context) error) error

WithTx provides a mock function with given fields: ctx, txFn

type MockTransactor_Expecter

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

func (*MockTransactor_Expecter) WithTx

func (_e *MockTransactor_Expecter) WithTx(ctx interface{}, txFn interface{}) *MockTransactor_WithTx_Call

WithTx is a helper method to define mock.On call

  • ctx context.Context
  • txFn func(context.Context) error

type MockTransactor_WithTx_Call

type MockTransactor_WithTx_Call struct {
	*mock.Call
}

MockTransactor_WithTx_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithTx'

func (*MockTransactor_WithTx_Call) Return

func (*MockTransactor_WithTx_Call) Run

func (*MockTransactor_WithTx_Call) RunAndReturn

type Transactor

type Transactor interface {
	// WithTx executes the given function inside a transaction.
	WithTx(ctx context.Context, txFn func(ctx context.Context) error) error
}

Transactor defines the methods related to database transaction.

Jump to

Keyboard shortcuts

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