mockdb

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2021 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoQueryHook       = fmt.Errorf("mockdb: no query hook found")
	ErrQueryValuesNil    = fmt.Errorf("mockdb: QueryValuesFunc is nil")
	ErrQueryRowValuesNil = fmt.Errorf("mockdb: QueryRowValuesFunc is nil")
	ErrResultValuesNil   = fmt.Errorf("mockdb: ResultValuesFunc is nil")
)

Functions

This section is empty.

Types

type HookCounter

type HookCounter interface {
	Name() string
	Triggered() int
}

type MockDB

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

func New

func New() *MockDB

func (*MockDB) AddHook

func (m *MockDB) AddHook(queryName string, query QueryValuesFunc, queryRow QueryRowValuesFunc, result ResultValuesFunc) HookCounter

func (*MockDB) AddQueryHook

func (m *MockDB) AddQueryHook(queryName string, queryFunc QueryValuesFunc) HookCounter

func (*MockDB) AddQueryResultHook

func (m *MockDB) AddQueryResultHook(queryName string, resultFunc ResultValuesFunc) HookCounter

func (*MockDB) AddQueryRowHook

func (m *MockDB) AddQueryRowHook(queryName string, queryRowFunc QueryRowValuesFunc) HookCounter

func (*MockDB) Begin

func (m *MockDB) Begin(context.Context, *sql.TxOptions) (db.Tx, error)

func (*MockDB) ClearHooks

func (m *MockDB) ClearHooks()

func (*MockDB) Exec

func (m *MockDB) Exec(_ context.Context, query *db.Query) (db.Result, error)

func (*MockDB) Ping

func (m *MockDB) Ping(context.Context) error

Ping is a NOP for MockDb

func (*MockDB) Query

func (m *MockDB) Query(_ context.Context, query *db.Query) (db.Rows, error)

func (*MockDB) QueryRow

func (m *MockDB) QueryRow(_ context.Context, query *db.Query) db.Row

func (*MockDB) RemoveHook

func (m *MockDB) RemoveHook(queryName string)

type QueryRowValuesFunc

type QueryRowValuesFunc func() []interface{}

QueryRowValuesFunc returns a single slice of column values

type QueryValuesFunc

type QueryValuesFunc func() [][]interface{}

QueryValuesFunc returns a slice of many column values

type ResultValuesFunc

type ResultValuesFunc func() (int64, int64)

ResultValuesFunc returns the last insert id and the number of rows affected

Jump to

Keyboard shortcuts

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