godb

package
v0.1.11 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// https://github.com/go-sql-driver/mysql
	MySQLDefaultParams = DBConnectionParams{
		"timeout":      defaultTimeout.String(),
		"readTimeout":  defaultTimeout.String(),
		"writeTimeout": defaultTimeout.String(),
	}

	// https://www.postgresql.org/docs/15/libpq-connect.html#LIBPQ-PARAMKEYWORDS
	// https://www.postgresql.org/docs/15/runtime-config-client.html
	// https://www.postgresql.org/docs/current/runtime-config-client.html
	PostgresDefaultParams = DBConnectionParams{
		"connect_timeout":   fmt.Sprintf("%d", defaultTimeout.Milliseconds()),
		"statement_timeout": fmt.Sprintf("%d", defaultTimeout.Milliseconds()),
		"sslmode":           "disable",
	}

	// https://pkg.go.dev/github.com/mattn/go-sqlite3
	SQLiteDefaultParams = DBConnectionParams{
		"cache": "private",
		"mode":  "memory",
	}
)
View Source
var (
	ErrUnknown                   = errors.New("unknown error")
	ErrInvalidDBType             = errors.New("invalid database type")
	ErrConnectionTimeoutExceeded = errors.New("connection timeout exceeded")
)

Functions

This section is empty.

Types

type Conn added in v0.1.8

type Conn interface {

	// Close returns the connection to the connection pool.
	// All operations after a Close will return with ErrConnDone.
	// Close is safe to call concurrently with other operations and will
	// block until all other operations finish. It may be useful to first
	// cancel any used context and then call close directly after.
	Close() error
	// ExecContext executes a query without returning any rows.
	// The args are for any placeholder parameters in the query.
	ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
	// PingContext verifies the connection to the database is still alive.
	PingContext(ctx context.Context) error
	// Raw executes f exposing the underlying driver connection for the
	// duration of f. The driverConn must not be used outside of f.
	//
	// Once f returns and err is not driver.ErrBadConn, the Conn will continue to be usable
	// until Conn.Close is called.
	Raw(f func(driverConn any) error) (err error)

	// BeginTx begins a transaction and returns an godb.Tx instead of an *sql.Tx.
	//
	// The provided context is used until the transaction is committed or rolled
	// back. If the context is canceled, the sql package will roll back the
	// transaction. Tx.Commit will return an error if the context provided to
	// BeginContext is canceled.
	BeginTx(ctx context.Context, opts *sql.TxOptions) (Tx, error)
	// GetContext using this godb.Conn.
	// Any placeholder parameters are replaced with supplied args.
	// An error is returned if the result set is empty.
	GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
	// PrepareContext returns an godb.Stmt instead of a sql.Stmt.
	//
	// The provided context is used for the preparation of the statement, not for
	// the execution of the statement.
	PrepareContext(ctx context.Context, query string) (Stmt, error)
	// QueryRowContext queries the database and returns an godb.Row.
	// Any placeholder parameters are replaced with supplied args.
	QueryRowContext(ctx context.Context, query string, args ...interface{}) Row
	// QueryContext queries the database and returns an godb.Rows.
	// Any placeholder parameters are replaced with supplied args.
	QueryContext(ctx context.Context, query string, args ...interface{}) (Rows, error)
	// Rebind a query within a Conn's bindvar type.
	Rebind(query string) string
	// SelectContext using this godb.Conn.
	// Any placeholder parameters are replaced with supplied args.
	SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
}

Conn defines a new connection

type ConnMock added in v0.1.8

type ConnMock struct {
	Error                   error
	CallbackClose           func() error
	CallbackExecContext     func(ctx context.Context, query string, args ...any) (sql.Result, error)
	CallbackPingContext     func(ctx context.Context) error
	CallbackRaw             func(f func(driverConn any) error) (err error)
	CallbackBeginTx         func(ctx context.Context, opts *sql.TxOptions) (Tx, error)
	CallbackGetContext      func(ctx context.Context, dest interface{}, query string, args ...interface{}) error
	CallbackPrepareContext  func(ctx context.Context, query string) (Stmt, error)
	CallbackQueryRowContext func(ctx context.Context, query string, args ...interface{}) Row
	CallbackQueryContext    func(ctx context.Context, query string, args ...interface{}) (Rows, error)
	CallbackRebind          func(query string) string
	CallbackSelectContext   func(ctx context.Context, dest interface{}, query string, args ...interface{}) error
}

ConnMock defines a new connection mock

func (*ConnMock) BeginTx added in v0.1.8

func (cm *ConnMock) BeginTx(ctx context.Context, opts *sql.TxOptions) (Tx, error)

BeginTx begins a transaction on the connection mock. If CallbackBeginTx is set, it will be called with the provided context and options, and its result will be returned. Otherwise, it returns a TxMock{} and the Error field of the ConnMock struct.

func (*ConnMock) Close added in v0.1.8

func (cm *ConnMock) Close() error

Close closes the connection mock. If CallbackClose is set, it will be called and its result will be returned. Otherwise, it returns the Error field of the ConnMock struct.

func (*ConnMock) ExecContext added in v0.1.8

func (cm *ConnMock) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)

ExecContext executes a query on the connection mock. If CallbackExecContext is set, it will be called with the provided arguments and its result will be returned. Otherwise, it returns a ResultMock{} and the Error field of the ConnMock struct.

func (*ConnMock) GetContext added in v0.1.8

func (cm *ConnMock) GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error

GetContext executes a query and retrieves the result on the connection mock. If CallbackGetContext is set, it will be called with the provided context, destination, query, and arguments, and its result will be returned. Otherwise, it returns the Error field of the ConnMock struct.

func (*ConnMock) PingContext added in v0.1.8

func (cm *ConnMock) PingContext(ctx context.Context) error

PingContext pings the connection mock. If CallbackPingContext is set, it will be called with the provided context and its result will be returned. Otherwise, it returns the Error field of the ConnMock struct.

func (*ConnMock) PrepareContext added in v0.1.8

func (cm *ConnMock) PrepareContext(ctx context.Context, query string) (Stmt, error)

PrepareContext prepares a statement on the connection mock. If CallbackPrepareContext is set, it will be called with the provided context and query, and its result will be returned. Otherwise, it returns a StatementMock{} and the Error field of the ConnMock struct.

func (*ConnMock) QueryContext added in v0.1.8

func (cm *ConnMock) QueryContext(ctx context.Context, query string, args ...interface{}) (Rows, error)

QueryContext executes a query and returns the result on the connection mock. If CallbackQueryContext is set, it will be called with the provided context, query, and arguments, and its result will be returned. Otherwise, it returns a RowsMock{} and the Error field of the ConnMock struct.

func (*ConnMock) QueryRowContext added in v0.1.8

func (cm *ConnMock) QueryRowContext(ctx context.Context, query string, args ...interface{}) Row

QueryRowContext executes a query and returns a single row on the connection mock. If CallbackQueryRowContext is set, it will be called with the provided context, query, and arguments, and its result will be returned. Otherwise, it returns a RowMock{}.

func (*ConnMock) Raw added in v0.1.8

func (cm *ConnMock) Raw(f func(driverConn any) error) (err error)

Raw executes a raw function on the connection mock. If CallbackRaw is set, it will be called with the provided function and its result will be returned. Otherwise, it returns the Error field of the ConnMock struct.

func (*ConnMock) Rebind added in v0.1.8

func (cm *ConnMock) Rebind(query string) string

Rebind rebinds a query on the connection mock. If CallbackRebind is set, it will be called with the provided query, and its result will be returned. Otherwise, it returns an empty string.

func (*ConnMock) SelectContext added in v0.1.8

func (cm *ConnMock) SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error

SelectContext executes a query and maps the result to a destination on the connection mock. If CallbackSelectContext is set, it will be called with the provided context, destination, query, and arguments, and its result will be returned. Otherwise, it returns the Error field of the ConnMock struct.

type DB added in v0.1.8

type DB interface {

	// Close closes the database and prevents new queries from starting.
	// Close then waits for all queries that have started processing on the server
	// to finish.
	//
	// It is rare to Close a godb.DB, as the godb.DB handle is meant to be
	// long-lived and shared between many goroutines.
	Close() error
	// Driver returns the database's underlying driver.
	Driver() driver.Driver
	// Exec executes a query without returning any rows.
	// The args are for any placeholder parameters in the query.
	//
	// Exec uses context.Background internally; to specify the context, use
	// ExecContext.
	Exec(query string, args ...any) (sql.Result, error)
	// ExecContext executes a query without returning any rows.
	// The args are for any placeholder parameters in the query.
	ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
	// Ping verifies a connection to the database is still alive,
	// establishing a connection if necessary.
	//
	// Ping uses context.Background internally; to specify the context, use
	// PingContext.
	Ping() error
	// PingContext verifies a connection to the database is still alive,
	// establishing a connection if necessary.
	PingContext(ctx context.Context) error
	// SetConnMaxIdleTime sets the maximum amount of time a connection may be idle.
	//
	// Expired connections may be closed lazily before reuse.
	//
	// If d <= 0, connections are not closed due to a connection's idle time.
	SetConnMaxIdleTime(d time.Duration)
	// SetConnMaxLifetime sets the maximum amount of time a connection may be reused.
	//
	// Expired connections may be closed lazily before reuse.
	//
	// If d <= 0, connections are not closed due to a connection's age.
	SetConnMaxLifetime(d time.Duration)
	// SetMaxIdleConns sets the maximum number of connections in the idle
	// connection pool.
	//
	// If MaxOpenConns is greater than 0 but less than the new MaxIdleConns,
	// then the new MaxIdleConns will be reduced to match the MaxOpenConns limit.
	//
	// If n <= 0, no idle connections are retained.
	//
	// The default max idle connections is currently 2. This may change in
	// a future release.
	SetMaxIdleConns(n int)
	// SetMaxOpenConns sets the maximum number of open connections to the database.
	//
	// If MaxIdleConns is greater than 0 and the new MaxOpenConns is less than
	// MaxIdleConns, then MaxIdleConns will be reduced to match the new
	// MaxOpenConns limit.
	//
	// If n <= 0, then there is no limit on the number of open connections.
	// The default is 0 (unlimited).
	SetMaxOpenConns(n int)
	// Stats returns database statistics.
	Stats() sql.DBStats

	// BeginTx begins a transaction and returns an godb.Tx instead of an *sql.Tx.
	//
	// The provided context is used until the transaction is committed or rolled
	// back. If the context is canceled, the sql package will roll back the
	// transaction. Tx.Commit will return an error if the context provided to
	// BeginxContext is canceled.
	BeginTx(ctx context.Context, opts *sql.TxOptions) (Tx, error)
	// Begin begins a transaction and returns an godb.Tx instead of an *sql.Tx.
	Begin() (Tx, error)
	// BindNamed binds a query using the DB driver's bindvar type.
	BindNamed(query string, arg interface{}) (string, []interface{}, error)
	// Conn returns an godb.Conn instead of an *sql.Conn.
	Conn(ctx context.Context) (Conn, error)
	// DriverName returns the driverName passed to the Open function for this DB.
	DriverName() string
	// Get using this DB.
	// Any placeholder parameters are replaced with supplied args.
	// An error is returned if the result set is empty.
	Get(dest interface{}, query string, args ...interface{}) error
	// GetContext using this DB.
	// Any placeholder parameters are replaced with supplied args.
	// An error is returned if the result set is empty.
	GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
	// MapperFunc sets a new mapper for this db using the default sqlx struct tag
	// and the provided mapper function.
	MapperFunc(mf func(string) string)
	// MustBegin starts a transaction, and panics on error.  Returns an godb.Tx instead
	// of an *sql.Tx.
	MustBegin() Tx
	// MustBeginTx starts a transaction, and panics on error.  Returns an godb.Tx instead
	// of an *sql.Tx.
	//
	// The provided context is used until the transaction is committed or rolled
	// back. If the context is canceled, the sql package will roll back the
	// transaction. Tx.Commit will return an error if the context provided to
	// MustBeginContext is canceled.
	MustBeginTx(ctx context.Context, opts *sql.TxOptions) Tx
	// MustExec (panic) runs MustExec using this database.
	// Any placeholder parameters are replaced with supplied args.
	MustExec(query string, args ...interface{}) sql.Result
	// MustExecContext (panic) runs MustExec using this database.
	// Any placeholder parameters are replaced with supplied args.
	MustExecContext(ctx context.Context, query string, args ...interface{}) sql.Result
	// NamedExec using this DB.
	// Any named placeholder parameters are replaced with fields from arg.
	NamedExec(query string, arg interface{}) (sql.Result, error)
	// NamedExecContext using this DB.
	// Any named placeholder parameters are replaced with fields from arg.
	NamedExecContext(ctx context.Context, query string, arg interface{}) (sql.Result, error)
	// NamedQuery using this DB.
	// Any named placeholder parameters are replaced with fields from arg.
	NamedQuery(query string, arg interface{}) (Rows, error)
	// NamedQueryContext using this DB.
	// Any named placeholder parameters are replaced with fields from arg.
	NamedQueryContext(ctx context.Context, query string, arg interface{}) (Rows, error)
	// PrepareNamed returns an godb.NamedStmt
	PrepareNamed(query string) (NamedStmt, error)
	// PrepareNamedContext returns an godb.NamedStmt
	PrepareNamedContext(ctx context.Context, query string) (NamedStmt, error)
	// Prepare returns an godb.Stmt instead of a sql.Stmt
	Prepare(query string) (Stmt, error)
	// PrepareContext returns an godb.Stmt instead of a sql.Stmt.
	//
	// The provided context is used for the preparation of the statement, not for
	// the execution of the statement.
	PrepareContext(ctx context.Context, query string) (Stmt, error)
	// QueryRow queries the database and returns an Row.
	// Any placeholder parameters are replaced with supplied args.
	QueryRow(query string, args ...interface{}) Row
	// QueryRowContext queries the database and returns an Row.
	// Any placeholder parameters are replaced with supplied args.
	QueryRowContext(ctx context.Context, query string, args ...interface{}) Row
	// Query queries the database and returns an Rows.
	// Any placeholder parameters are replaced with supplied args.
	Query(query string, args ...interface{}) (Rows, error)
	// QueryContext queries the database and returns an Rows.
	// Any placeholder parameters are replaced with supplied args.
	QueryContext(ctx context.Context, query string, args ...interface{}) (Rows, error)
	// Rebind transforms a query from QUESTION to the DB driver's bindvar type.
	Rebind(query string) string
	// Select using this DB.
	// Any placeholder parameters are replaced with supplied args.
	Select(dest interface{}, query string, args ...interface{}) error
	// SelectContext using this DB.
	// Any placeholder parameters are replaced with supplied args.
	SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
	// Unsafe returns a version of DB which will silently succeed to scan when
	// columns in the SQL result have no fields in the destination struct.
	// godb.Stmt and godb.Tx which are created from this DB will inherit its
	// safety behavior.
	Unsafe() *sqlx.DB
	// Safe returns the underlying DB
	Safe() *sqlx.DB
	// contains filtered or unexported methods
}

Define database interface

func NewDB added in v0.1.8

func NewDB(config DBConfig) (DB, error)

NewDB Returns a new database connection

type DBConfig

type DBConfig struct {
	Host             string
	Port             string
	User             string
	Password         string
	Database         string
	DatabaseType     DBType
	ConnectTimeout   time.Duration
	ConnectionParams DBConnectionParams
}

Define all database configs

type DBConnectionParams

type DBConnectionParams map[string]string

type DBMock added in v0.1.8

type DBMock struct {
	Error                       error
	CallbackpopTestError        func() error
	CallbackpushTestError       func(err error)
	CallbackClose               func() error
	CallbackDriver              func() driver.Driver
	CallbackExec                func(query string, args ...any) (sql.Result, error)
	CallbackExecContext         func(ctx context.Context, query string, args ...any) (sql.Result, error)
	CallbackPing                func() error
	CallbackPingContext         func(ctx context.Context) error
	CallbackSetConnMaxIdleTime  func(d time.Duration)
	CallbackSetConnMaxLifetime  func(d time.Duration)
	CallbackSetMaxOpenConns     func(n int)
	CallbackSetMaxIdleConns     func(n int)
	CallbackStats               func() sql.DBStats
	CallbackBeginTx             func(ctx context.Context, opts *sql.TxOptions) (Tx, error)
	CallbackBegin               func() (Tx, error)
	CallbackBindNamed           func(query string, arg interface{}) (string, []interface{}, error)
	CallbackConn                func(ctx context.Context) (Conn, error)
	CallbackDriverName          func() string
	CallbackGet                 func(dest interface{}, query string, args ...interface{}) error
	CallbackGetContext          func(ctx context.Context, dest interface{}, query string, args ...interface{}) error
	CallbackMapperFunc          func(mf func(string) string)
	CallbackMustBegin           func() Tx
	CallbackMustBeginTx         func(ctx context.Context, opts *sql.TxOptions) Tx
	CallbackMustExec            func(query string, args ...interface{}) sql.Result
	CallbackMustExecContext     func(ctx context.Context, query string, args ...interface{}) sql.Result
	CallbackNamedExec           func(query string, arg interface{}) (sql.Result, error)
	CallbackNamedExecContext    func(ctx context.Context, query string, arg interface{}) (sql.Result, error)
	CallbackNamedQuery          func(query string, arg interface{}) (Rows, error)
	CallbackNamedQueryContext   func(ctx context.Context, query string, arg interface{}) (Rows, error)
	CallbackPrepareNamed        func(query string) (NamedStmt, error)
	CallbackPrepareNamedContext func(ctx context.Context, query string) (NamedStmt, error)
	CallbackPrepare             func(query string) (Stmt, error)
	CallbackPrepareContext      func(ctx context.Context, query string) (Stmt, error)
	CallbackQueryRow            func(query string, args ...interface{}) Row
	CallbackQueryRowContext     func(ctx context.Context, query string, args ...interface{}) Row
	CallbackQuery               func(query string, args ...interface{}) (Rows, error)
	CallbackQueryContext        func(ctx context.Context, query string, args ...interface{}) (Rows, error)
	CallbackRebind              func(query string) string
	CallbackSelect              func(dest interface{}, query string, args ...interface{}) error
	CallbackSelectContext       func(ctx context.Context, dest interface{}, query string, args ...interface{}) error
	CallbackUnsafe              func() *sqlx.DB
	CallbackSafe                func() *sqlx.DB
}

DBMock is a mock implementation of the sql.DB interface.

func NewMockDB added in v0.1.8

func NewMockDB() *DBMock

NewMockDB creates a new instance of DBMock.

func (*DBMock) Begin added in v0.1.8

func (dbm *DBMock) Begin() (Tx, error)

Begin calls the callback function CallbackBegin if it is set. Otherwise, it returns a new instance of TxMock.

func (*DBMock) BeginTx added in v0.1.8

func (dbm *DBMock) BeginTx(ctx context.Context, opts *sql.TxOptions) (Tx, error)

BeginTx calls the callback function CallbackBeginTx if it is set. Otherwise, it returns a new instance of TxMock.

func (*DBMock) BindNamed added in v0.1.8

func (dbm *DBMock) BindNamed(query string, arg interface{}) (string, []interface{}, error)

BindNamed calls the callback function CallbackBindNamed if it is set. Otherwise, it returns an empty string and an empty slice of interfaces.

func (*DBMock) Close added in v0.1.8

func (dbm *DBMock) Close() error

Close calls the callback function CallbackClose if it is set. Otherwise, it returns the Error field of the DBMock.

func (*DBMock) Conn added in v0.1.8

func (dbm *DBMock) Conn(ctx context.Context) (Conn, error)

Conn calls the callback function CallbackConn if it is set. Otherwise, it returns a new instance of ConnMock.

func (*DBMock) Driver added in v0.1.8

func (dbm *DBMock) Driver() driver.Driver

Driver calls the callback function CallbackDriver if it is set. Otherwise, it returns a new instance of DriverMock.

func (*DBMock) DriverName added in v0.1.8

func (dbm *DBMock) DriverName() string

DriverName calls the callback function CallbackDriverName if it is set.

func (*DBMock) Exec added in v0.1.8

func (dbm *DBMock) Exec(query string, args ...any) (sql.Result, error)

Exec calls the callback function CallbackExec if it is set. Otherwise, it returns a new instance of ResultMock.

func (*DBMock) ExecContext added in v0.1.8

func (dbm *DBMock) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)

ExecContext calls the callback function CallbackExecContext if it is set. Otherwise, it returns a new instance of ResultMock.

func (*DBMock) Get added in v0.1.8

func (dbm *DBMock) Get(dest interface{}, query string, args ...interface{}) error

Get calls the callback function CallbackGet if it is set. Otherwise, it returns the Error field of the DBMock.

func (*DBMock) GetContext added in v0.1.8

func (dbm *DBMock) GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error

GetContext calls the callback function CallbackGetContext if it is set. Otherwise, it returns the Error field of the DBMock.

func (*DBMock) MapperFunc added in v0.1.8

func (dbm *DBMock) MapperFunc(mf func(string) string)

MapperFunc calls the callback function CallbackMapperFunc if it is set. Otherwise, it returns the Error field of the DBMock.

func (*DBMock) MustBegin added in v0.1.8

func (dbm *DBMock) MustBegin() Tx

MustBegin calls the callback function CallbackMustBegin if it is set. Otherwise, it returns a new instance of TxMock.

func (*DBMock) MustBeginTx added in v0.1.8

func (dbm *DBMock) MustBeginTx(ctx context.Context, opts *sql.TxOptions) Tx

MustBeginTx calls the callback function CallbackMustBeginTx if it is set. Otherwise, it returns a new instance of TxMock.

func (*DBMock) MustExec added in v0.1.8

func (dbm *DBMock) MustExec(query string, args ...interface{}) sql.Result

MustExec calls the callback function CallbackMustExec if it is set. Otherwise, it returns a new instance of ResultMock.

func (*DBMock) MustExecContext added in v0.1.8

func (dbm *DBMock) MustExecContext(ctx context.Context, query string, args ...interface{}) sql.Result

MustExecContext calls the callback function CallbackMustExecContext if it is set. Otherwise, it returns a new instance of ResultMock.

func (*DBMock) NamedExec added in v0.1.8

func (dbm *DBMock) NamedExec(query string, arg interface{}) (sql.Result, error)

NamedExec calls the callback function CallbackNamedExec if it is set. Otherwise, it returns a new instance of ResultMock.

func (*DBMock) NamedExecContext added in v0.1.8

func (dbm *DBMock) NamedExecContext(ctx context.Context, query string, arg interface{}) (sql.Result, error)

NamedExecContext calls the callback function CallbackNamedExecContext if it is set. Otherwise, it returns a new instance of ResultMock.

func (*DBMock) NamedQuery added in v0.1.8

func (dbm *DBMock) NamedQuery(query string, arg interface{}) (Rows, error)

NamedQuery calls the callback function CallbackNamedQuery if it is set. Otherwise, it returns a new instance of RowsMock.

func (*DBMock) NamedQueryContext added in v0.1.8

func (dbm *DBMock) NamedQueryContext(ctx context.Context, query string, arg interface{}) (Rows, error)

NamedQueryContext calls the callback function CallbackNamedQueryContext if it is set. Otherwise, it returns a new instance of RowsMock.

func (*DBMock) Ping added in v0.1.8

func (dbm *DBMock) Ping() error

Ping calls the callback function CallbackPing if it is set. Otherwise, it returns the Error field of the DBMock.

func (*DBMock) PingContext added in v0.1.8

func (dbm *DBMock) PingContext(ctx context.Context) error

PingContext calls the callback function CallbackPingContext if it is set. Otherwise, it returns the Error field of the DBMock.

func (*DBMock) Prepare added in v0.1.8

func (dbm *DBMock) Prepare(query string) (Stmt, error)

Prepare calls the callback function CallbackPrepare if it is set. Otherwise, it returns a new instance of StatementMock.

func (*DBMock) PrepareContext added in v0.1.8

func (dbm *DBMock) PrepareContext(ctx context.Context, query string) (Stmt, error)

PrepareContext calls the callback function CallbackPrepareContext if it is set. Otherwise, it returns a new instance of StatementMock.

func (*DBMock) PrepareNamed added in v0.1.8

func (dbm *DBMock) PrepareNamed(query string) (NamedStmt, error)

PrepareNamed calls the callback function CallbackPrepareNamed if it is set. Otherwise, it returns a new instance of NamedStmtMock.

func (*DBMock) PrepareNamedContext added in v0.1.8

func (dbm *DBMock) PrepareNamedContext(ctx context.Context, query string) (NamedStmt, error)

PrepareNamedContext calls the callback function CallbackPrepareNamedContext if it is set. Otherwise, it returns a new instance of NamedStmtMock.

func (*DBMock) Query added in v0.1.8

func (dbm *DBMock) Query(query string, args ...interface{}) (Rows, error)

Query calls the callback function CallbackQuery if it is set. Otherwise, it returns a new instance of RowsMock.

func (*DBMock) QueryContext added in v0.1.8

func (dbm *DBMock) QueryContext(ctx context.Context, query string, args ...interface{}) (Rows, error)

QueryContext calls the callback function CallbackQueryContext if it is set. Otherwise, it returns a new instance of RowsMock.

func (*DBMock) QueryRow added in v0.1.8

func (dbm *DBMock) QueryRow(query string, args ...interface{}) Row

QueryRow calls the callback function CallbackQueryRow if it is set. Otherwise, it returns a new instance of RowMock.

func (*DBMock) QueryRowContext added in v0.1.8

func (dbm *DBMock) QueryRowContext(ctx context.Context, query string, args ...interface{}) Row

QueryRowContext calls the callback function CallbackQueryRowContext if it is set. Otherwise, it returns a new instance of RowMock.

func (*DBMock) Rebind added in v0.1.8

func (dbm *DBMock) Rebind(query string) string

Rebind calls the callback function CallbackRebind if it is set. Otherwise, it returns an empty string.

func (*DBMock) Safe added in v0.1.8

func (dbm *DBMock) Safe() *sqlx.DB

Safe calls the callback function CallbackSafe if it is set. Otherwise, it returns a new instance of sqlx.DB.

func (*DBMock) Select added in v0.1.8

func (dbm *DBMock) Select(dest interface{}, query string, args ...interface{}) error

Select calls the callback function CallbackSelect if it is set. Otherwise, it returns the Error field of the DBMock.

func (*DBMock) SelectContext added in v0.1.8

func (dbm *DBMock) SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error

SelectContext calls the callback function CallbackSelectContext if it is set. Otherwise, it returns the Error field of the DBMock.

func (*DBMock) SetConnMaxIdleTime added in v0.1.8

func (dbm *DBMock) SetConnMaxIdleTime(d time.Duration)

SetConnMaxIdleTime calls the callback function CallbackSetConnMaxIdleTime if it is set.

func (*DBMock) SetConnMaxLifetime added in v0.1.8

func (dbm *DBMock) SetConnMaxLifetime(d time.Duration)

SetConnMaxLifetime calls the callback function CallbackSetConnMaxLifetime if it is set.

func (*DBMock) SetMaxIdleConns added in v0.1.8

func (dbm *DBMock) SetMaxIdleConns(n int)

SetMaxIdleConns calls the callback function CallbackSetMaxIdleConns if it is set.

func (*DBMock) SetMaxOpenConns added in v0.1.8

func (dbm *DBMock) SetMaxOpenConns(n int)

SetMaxOpenConns calls the callback function CallbackSetMaxOpenConns if it is set.

func (*DBMock) Stats added in v0.1.8

func (dbm *DBMock) Stats() sql.DBStats

Stats calls the callback function CallbackStats if it is set.

func (*DBMock) Unsafe added in v0.1.8

func (dbm *DBMock) Unsafe() *sqlx.DB

Unsafe calls the callback function CallbackUnsafe if it is set. Otherwise, it returns a new instance of sqlx.DB.

type DBType

type DBType uint
const (
	MySQLDB DBType = iota + 1
	SQLiteDB
	PostgresDB
)

func (DBType) String

func (dbt DBType) String() string

String return DBType as string

type DriverConnMock added in v0.1.8

type DriverConnMock struct {
	Error           error
	CallbackPrepare func(query string) (driver.Stmt, error)
	CallbackClose   func() error
	CallbackBegin   func() (driver.Tx, error)
}

DriverConnMock defines a new driver connection mock

func (*DriverConnMock) Begin added in v0.1.8

func (dcm *DriverConnMock) Begin() (driver.Tx, error)

Begin starts a new transaction. If CallbackBegin is defined, it calls the callback function. Otherwise, it returns a new DriverTxMock and the error defined in the struct.

func (*DriverConnMock) Close added in v0.1.8

func (dcm *DriverConnMock) Close() error

Close closes the connection. If CallbackClose is defined, it calls the callback function. Otherwise, it returns the error defined in the struct.

func (*DriverConnMock) Prepare added in v0.1.8

func (dcm *DriverConnMock) Prepare(query string) (driver.Stmt, error)

Prepare prepares a statement for execution. If CallbackPrepare is defined, it calls the callback function. Otherwise, it returns a new DriverStmtMock and the error defined in the struct.

type DriverMock added in v0.1.8

type DriverMock struct {
	Error        error
	CallbackOpen func(name string) (driver.Conn, error)
}

DriverMock defines a new driver mock

func (*DriverMock) Open added in v0.1.8

func (dm *DriverMock) Open(name string) (driver.Conn, error)

Open opens a new connection. If CallbackOpen is defined, it calls the callback function. Otherwise, it returns a new DriverConnMock and the error defined in the struct.

type DriverResultMock added in v0.1.8

type DriverResultMock struct {
	Error                error
	CallbackLastInsertId func() (int64, error)
	CallbackRowsAffected func() (int64, error)
}

DriverResultMock defines a new driver result mock

func (*DriverResultMock) LastInsertId added in v0.1.8

func (drm *DriverResultMock) LastInsertId() (int64, error)

LastInsertId returns the last inserted row id. If CallbackLastInsertId is defined, it calls the callback function. Otherwise, it returns 0 and the error defined in the struct.

func (*DriverResultMock) RowsAffected added in v0.1.8

func (drm *DriverResultMock) RowsAffected() (int64, error)

RowsAffected returns the number of rows affected by the query. If CallbackRowsAffected is defined, it calls the callback function. Otherwise, it returns 0 and the error defined in the struct.

type DriverRowsMock added in v0.1.8

type DriverRowsMock struct {
	Error           error
	CallbackColumns func() []string
	CallbackClose   func() error
	CallbackNext    func(dest []driver.Value) error
}

DriverRowsMock defines a new driver rows mock It provides callback functions for each method to allow custom behavior during testing.

func (*DriverRowsMock) Close added in v0.1.8

func (drm *DriverRowsMock) Close() error

Close closes the rows. If CallbackClose is defined, it calls the callback function. Otherwise, it returns the error defined in the struct.

func (*DriverRowsMock) Columns added in v0.1.8

func (drm *DriverRowsMock) Columns() []string

Columns returns the column names of the rows. If CallbackColumns is defined, it calls the callback function. Otherwise, it returns an empty slice.

func (*DriverRowsMock) Next added in v0.1.8

func (drm *DriverRowsMock) Next(dest []driver.Value) error

Next retrieves the next row of the result set. If CallbackNext is defined, it calls the callback function. Otherwise, it returns the error defined in the struct.

type DriverStmtMock added in v0.1.8

type DriverStmtMock struct {
	Error            error
	CallbackClose    func() error
	CallbackNumInput func() int
	CallbackExec     func(args []driver.Value) (driver.Result, error)
	CallbackQuery    func(args []driver.Value) (driver.Rows, error)
}

DriverStmtMock defines a new driver statement mock

func (*DriverStmtMock) Close added in v0.1.8

func (dsm *DriverStmtMock) Close() error

Close closes the statement. If CallbackClose is defined, it calls the callback function. Otherwise, it returns the error defined in the struct.

func (*DriverStmtMock) Exec added in v0.1.8

func (dsm *DriverStmtMock) Exec(args []driver.Value) (driver.Result, error)

Exec executes a query that doesn't return rows. If CallbackExec is defined, it calls the callback function. Otherwise, it returns a new DriverResultMock and the error defined in the struct.

func (*DriverStmtMock) NumInput added in v0.1.8

func (dsm *DriverStmtMock) NumInput() int

NumInput returns the number of placeholder parameters in the statement. If CallbackNumInput is defined, it calls the callback function. Otherwise, it returns 0.

func (*DriverStmtMock) Query added in v0.1.8

func (dsm *DriverStmtMock) Query(args []driver.Value) (driver.Rows, error)

Query executes a query that may return rows. If CallbackQuery is defined, it calls the callback function. Otherwise, it returns a new DriverRowsMock and the error defined in the struct.

type DriverTxMock added in v0.1.8

type DriverTxMock struct {
	Error            error
	CallbackCommit   func() error
	CallbackRollback func() error
}

DriverTxMock defines a new driver transaction mock

func (*DriverTxMock) Commit added in v0.1.8

func (dtxm *DriverTxMock) Commit() error

Commit commits the transaction. If CallbackCommit is defined, it calls the callback function. Otherwise, it returns the error defined in the struct.

func (*DriverTxMock) Rollback added in v0.1.8

func (dtxm *DriverTxMock) Rollback() error

Rollback rolls back the transaction. If CallbackRollback is defined, it calls the callback function. Otherwise, it returns the error defined in the struct.

type NamedStmt added in v0.1.8

type NamedStmt interface {

	// Close closes the named statement.
	Close() error
	// Exec executes a named statement using the struct passed.
	// Any named placeholder parameters are replaced with fields from arg.
	Exec(arg interface{}) (sql.Result, error)
	// ExecContext executes a named statement using the struct passed.
	// Any named placeholder parameters are replaced with fields from arg.
	ExecContext(ctx context.Context, arg interface{}) (sql.Result, error)
	// Get using this NamedStmt
	// Any named placeholder parameters are replaced with fields from arg.
	Get(dest interface{}, arg interface{}) error
	// GetContext using this NamedStmt
	// Any named placeholder parameters are replaced with fields from arg.
	GetContext(ctx context.Context, dest interface{}, arg interface{}) error
	// MustExec execs a NamedStmt, panicing on error
	// Any named placeholder parameters are replaced with fields from arg.
	MustExec(arg interface{}) sql.Result
	// MustExecContext execs a NamedStmt, panicing on error
	// Any named placeholder parameters are replaced with fields from arg.
	MustExecContext(ctx context.Context, arg interface{}) sql.Result
	// QueryRow this NamedStmt.  Because of limitations with QueryRow, this is
	// an alias for QueryRow.
	// Any named placeholder parameters are replaced with fields from arg.
	QueryRow(arg interface{}) Row
	// QueryRowContext this NamedStmt.  Because of limitations with QueryRow, this is
	// an alias for QueryRow.
	// Any named placeholder parameters are replaced with fields from arg.
	QueryRowContext(ctx context.Context, arg interface{}) Row
	// Query using this NamedStmt
	// Any named placeholder parameters are replaced with fields from arg.
	Query(arg interface{}) (Rows, error)
	// QueryContext using this NamedStmt
	// Any named placeholder parameters are replaced with fields from arg.
	QueryContext(ctx context.Context, arg interface{}) (Rows, error)
	// Select using this NamedStmt
	// Any named placeholder parameters are replaced with fields from arg.
	Select(dest interface{}, arg interface{}) error
	// SelectContext using this NamedStmt
	// Any named placeholder parameters are replaced with fields from arg.
	SelectContext(ctx context.Context, dest interface{}, arg interface{}) error
	// Unsafe returns an unsafe version of the NamedStmt
	Unsafe() *sqlx.NamedStmt
	// Safe returns the underlying named statement
	Safe() *sqlx.NamedStmt
}

Defines the named statement

type NamedStmtMock added in v0.1.8

type NamedStmtMock struct {
	Error                   error
	CallbackClose           func() error
	CallbackExec            func(arg interface{}) (sql.Result, error)
	CallbackExecContext     func(ctx context.Context, arg interface{}) (sql.Result, error)
	CallbackGet             func(dest interface{}, arg interface{}) error
	CallbackGetContext      func(ctx context.Context, dest interface{}, arg interface{}) error
	CallbackMustExec        func(arg interface{}) sql.Result
	CallbackMustExecContext func(ctx context.Context, arg interface{}) sql.Result
	CallbackQueryRow        func(arg interface{}) Row
	CallbackQueryRowContext func(ctx context.Context, arg interface{}) Row
	CallbackQuery           func(arg interface{}) (Rows, error)
	CallbackQueryContext    func(ctx context.Context, arg interface{}) (Rows, error)
	CallbackSelect          func(dest interface{}, arg interface{}) error
	CallbackSelectContext   func(ctx context.Context, dest interface{}, arg interface{}) error
	CallbackUnsafe          func() *sqlx.NamedStmt
	CallbackSafe            func() *sqlx.NamedStmt
}

NamedStmtMock is a mock implementation of sqlx.NamedStmt. It provides callback functions for each method to allow custom behavior during testing.

func (*NamedStmtMock) Close added in v0.1.8

func (nsm *NamedStmtMock) Close() error

Close calls the callback function CallbackClose if it is set. Otherwise, it returns the Error field of the NamedStmtMock.

func (*NamedStmtMock) Exec added in v0.1.8

func (nsm *NamedStmtMock) Exec(arg interface{}) (sql.Result, error)

Exec calls the callback function CallbackExec if it is set. Otherwise, it returns a ResultMock and the Error field of the NamedStmtMock.

func (*NamedStmtMock) ExecContext added in v0.1.8

func (nsm *NamedStmtMock) ExecContext(ctx context.Context, arg interface{}) (sql.Result, error)

ExecContext calls the callback function CallbackExecContext if it is set. Otherwise, it returns a ResultMock and the Error field of the NamedStmtMock.

func (*NamedStmtMock) Get added in v0.1.8

func (nsm *NamedStmtMock) Get(dest interface{}, arg interface{}) error

Get calls the callback function CallbackGet if it is set. Otherwise, it returns the Error field of the NamedStmtMock.

func (*NamedStmtMock) GetContext added in v0.1.8

func (nsm *NamedStmtMock) GetContext(ctx context.Context, dest interface{}, arg interface{}) error

GetContext calls the callback function CallbackGetContext if it is set. Otherwise, it returns the Error field of the NamedStmtMock.

func (*NamedStmtMock) MustExec added in v0.1.8

func (nsm *NamedStmtMock) MustExec(arg interface{}) sql.Result

MustExec calls the callback function CallbackMustExec if it is set. Otherwise, it returns a ResultMock.

func (*NamedStmtMock) MustExecContext added in v0.1.8

func (nsm *NamedStmtMock) MustExecContext(ctx context.Context, arg interface{}) sql.Result

MustExecContext calls the callback function CallbackMustExecContext if it is set. Otherwise, it returns a ResultMock.

func (*NamedStmtMock) Query added in v0.1.8

func (nsm *NamedStmtMock) Query(arg interface{}) (Rows, error)

Query calls the callback function CallbackQuery if it is set. Otherwise, it returns a RowsMock and the Error field of the NamedStmtMock.

func (*NamedStmtMock) QueryContext added in v0.1.8

func (nsm *NamedStmtMock) QueryContext(ctx context.Context, arg interface{}) (Rows, error)

QueryContext calls the callback function CallbackQueryContext if it is set. Otherwise, it returns a RowsMock and the Error field of the NamedStmtMock.

func (*NamedStmtMock) QueryRow added in v0.1.8

func (nsm *NamedStmtMock) QueryRow(arg interface{}) Row

QueryRow calls the callback function CallbackQueryRow if it is set. Otherwise, it returns a RowMock.

func (*NamedStmtMock) QueryRowContext added in v0.1.8

func (nsm *NamedStmtMock) QueryRowContext(ctx context.Context, arg interface{}) Row

QueryRowContext calls the callback function CallbackQueryRowContext if it is set. Otherwise, it returns a RowMock.

func (*NamedStmtMock) Safe added in v0.1.8

func (nsm *NamedStmtMock) Safe() *sqlx.NamedStmt

Safe calls the callback function CallbackSafe if it is set. Otherwise, it returns a new sqlx.NamedStmt.

func (*NamedStmtMock) Select added in v0.1.8

func (nsm *NamedStmtMock) Select(dest interface{}, arg interface{}) error

Select calls the callback function CallbackSelect if it is set. Otherwise, it returns the Error field of the NamedStmtMock.

func (*NamedStmtMock) SelectContext added in v0.1.8

func (nsm *NamedStmtMock) SelectContext(ctx context.Context, dest interface{}, arg interface{}) error

SelectContext calls the callback function CallbackSelectContext if it is set. Otherwise, it returns the Error field of the NamedStmtMock.

func (*NamedStmtMock) Unsafe added in v0.1.8

func (nsm *NamedStmtMock) Unsafe() *sqlx.NamedStmt

Unsafe calls the callback function CallbackUnsafe if it is set. Otherwise, it returns a new sqlx.NamedStmt.

type ResultMock added in v0.1.8

type ResultMock struct {
	Err                  error
	CallbackLastInsertId func() (int64, error)
	CallbackRowsAffected func() (int64, error)
}

ResultMock defines a mock for the sql.Result interface

func (*ResultMock) LastInsertId added in v0.1.8

func (rm *ResultMock) LastInsertId() (int64, error)

LastInsertId returns the last inserted row id. If a callback function is defined, it will be called to retrieve the value. Otherwise, it returns 0 and the error defined in ResultMock.Err.

func (*ResultMock) RowsAffected added in v0.1.8

func (rm *ResultMock) RowsAffected() (int64, error)

RowsAffected returns the number of rows affected by the query. If a callback function is defined, it will be called to retrieve the value. Otherwise, it returns 0 and the error defined in ResultMock.Err.

type Row added in v0.1.8

type Row interface {

	// ColumnTypes returns the underlying sql.Rows.ColumnTypes(), or the deferred error
	ColumnTypes() ([]*sql.ColumnType, error)
	// Columns returns the underlying sql.Rows.Columns(), or the deferred error usually
	// returned by Row.Scan()
	Columns() ([]string, error)
	// Err returns the error encountered while scanning
	Err() error
	// MapScan using this Rows
	MapScan(dest map[string]interface{}) error
	// Scan is a fixed implementation of sql.Row.Scan, which does not discard the
	// underlying error from the internal rows object if it exists
	Scan(dest ...interface{}) error
	// SliceScan using this Rows
	SliceScan() ([]interface{}, error)
	// StructScan a single Row into dest
	StructScan(dest interface{}) error
}

Row defines a new row

type RowMock added in v0.1.8

type RowMock struct {
	Error               error
	CallbackColumnTypes func() ([]*sql.ColumnType, error)
	CallbackColumns     func() ([]string, error)
	CallbackErr         func() error
	CallbackMapScan     func(dest map[string]interface{}) error
	CallbackScan        func(dest ...interface{}) error
	CallbackSliceScan   func() ([]interface{}, error)
	CallbackStructScan  func(dest interface{}) error
}

RowMock is a mock implementation of the sql.Row interface

func (*RowMock) ColumnTypes added in v0.1.8

func (rm *RowMock) ColumnTypes() ([]*sql.ColumnType, error)

ColumnTypes returns the column types of the row. If CallbackColumnTypes is defined, it calls the callback function. Otherwise, it returns an empty slice of sql.ColumnType and the stored error.

func (*RowMock) Columns added in v0.1.8

func (rm *RowMock) Columns() ([]string, error)

Columns returns the column names of the row. If CallbackColumns is defined, it calls the callback function. Otherwise, it returns an empty slice of strings and the stored error.

func (*RowMock) Err added in v0.1.8

func (rm *RowMock) Err() error

Err returns the error associated with the row. If CallbackErr is defined, it calls the callback function. Otherwise, it returns the stored error.

func (*RowMock) MapScan added in v0.1.8

func (rm *RowMock) MapScan(dest map[string]interface{}) error

MapScan scans the row into a map of column names to values. If CallbackMapScan is defined, it calls the callback function. Otherwise, it returns the stored error.

func (*RowMock) Scan added in v0.1.8

func (rm *RowMock) Scan(dest ...interface{}) error

Scan scans the row into the provided destination values. If CallbackScan is defined, it calls the callback function. Otherwise, it returns the stored error.

func (*RowMock) SliceScan added in v0.1.8

func (rm *RowMock) SliceScan() ([]interface{}, error)

SliceScan scans the row into a slice of interface{} values. If CallbackSliceScan is defined, it calls the callback function. Otherwise, it returns an empty slice of interface{} and the stored error.

func (*RowMock) StructScan added in v0.1.8

func (rm *RowMock) StructScan(dest interface{}) error

StructScan scans the row into the provided destination struct. If CallbackStructScan is defined, it calls the callback function. Otherwise, it returns the stored error.

type Rows added in v0.1.8

type Rows interface {

	// Close closes the Rows, preventing further enumeration. If Next is called
	// and returns false and there are no further result sets,
	// the Rows are closed automatically and it will suffice to check the
	// result of Err. Close is idempotent and does not affect the result of Err.
	Close() error
	// ColumnTypes returns column information such as column type, length,
	// and nullable. Some information may not be available from some drivers.
	ColumnTypes() ([]*sql.ColumnType, error)
	// Columns returns the column names.
	// Columns returns an error if the rows are closed.
	Columns() ([]string, error)
	// Err returns the error, if any, that was encountered during iteration.
	// Err may be called after an explicit or implicit Close.
	Err() error
	// Next prepares the next result row for reading with the Scan method. It
	// returns true on success, or false if there is no next result row or an error
	// happened while preparing it. Err should be consulted to distinguish between
	// the two cases.
	//
	// Every call to Scan, even the first one, must be preceded by a call to Next.
	Next() bool
	// NextResultSet prepares the next result set for reading. It reports whether
	// there is further result sets, or false if there is no further result set
	// or if there is an error advancing to it. The Err method should be consulted
	// to distinguish between the two cases.
	//
	// After calling NextResultSet, the Next method should always be called before
	// scanning. If there are further result sets they may not have rows in the result
	// set.
	NextResultSet() bool
	// Scan copies the columns in the current row into the values pointed
	// at by dest. The number of values in dest must be the same as the
	// number of columns in Rows.
	//
	// Scan converts columns read from the database into the following
	// common Go types and special types provided by the sql package:
	//
	//	*string
	//	*[]byte
	//	*int, *int8, *int16, *int32, *int64
	//	*uint, *uint8, *uint16, *uint32, *uint64
	//	*bool
	//	*float32, *float64
	//	*interface{}
	//	*RawBytes
	//	*Rows (cursor value)
	//	any type implementing Scanner (see Scanner docs)
	//
	// In the most simple case, if the type of the value from the source
	// column is an integer, bool or string type T and dest is of type *T,
	// Scan simply assigns the value through the pointer.
	//
	// Scan also converts between string and numeric types, as long as no
	// information would be lost. While Scan stringifies all numbers
	// scanned from numeric database columns into *string, scans into
	// numeric types are checked for overflow. For example, a float64 with
	// value 300 or a string with value "300" can scan into a uint16, but
	// not into a uint8, though float64(255) or "255" can scan into a
	// uint8. One exception is that scans of some float64 numbers to
	// strings may lose information when stringifying. In general, scan
	// floating point columns into *float64.
	//
	// If a dest argument has type *[]byte, Scan saves in that argument a
	// copy of the corresponding data. The copy is owned by the caller and
	// can be modified and held indefinitely. The copy can be avoided by
	// using an argument of type *RawBytes instead; see the documentation
	// for RawBytes for restrictions on its use.
	//
	// If an argument has type *interface{}, Scan copies the value
	// provided by the underlying driver without conversion. When scanning
	// from a source value of type []byte to *interface{}, a copy of the
	// slice is made and the caller owns the result.
	//
	// Source values of type time.Time may be scanned into values of type
	// *time.Time, *interface{}, *string, or *[]byte. When converting to
	// the latter two, time.RFC3339Nano is used.
	//
	// Source values of type bool may be scanned into types *bool,
	// *interface{}, *string, *[]byte, or *RawBytes.
	//
	// For scanning into *bool, the source may be true, false, 1, 0, or
	// string inputs parseable by strconv.ParseBool.
	//
	// Scan can also convert a cursor returned from a query, such as
	// "select cursor(select * from my_table) from dual", into a
	// *Rows value that can itself be scanned from. The parent
	// select query will close any cursor *Rows if the parent *Rows is closed.
	//
	// If any of the first arguments implementing Scanner returns an error,
	// that error will be wrapped in the returned error.
	Scan(dest ...any) error

	// MapScan using this Rows.
	MapScan(dest map[string]interface{}) error
	// SliceScan using this Rows.
	SliceScan() ([]interface{}, error)
	// StructScan is like sql.Rows.Scan, but scans a single Row into a single Struct.
	// Use this and iterate over Rows manually when the memory load of Select() might be
	// prohibitive.  *Rows.StructScan caches the reflect work of matching up column
	// positions to fields to avoid that overhead per scan, which means it is not safe
	// to run StructScan on the same Rows instance with different struct types.
	StructScan(dest interface{}) error
}

Rows defines a new row

type RowsMock added in v0.1.8

type RowsMock struct {
	Error                 error
	CallbackClose         func() error
	CallbackColumnTypes   func() ([]*sql.ColumnType, error)
	CallbackColumns       func() ([]string, error)
	CallbackErr           func() error
	CallbackNext          func() bool
	CallbackNextResultSet func() bool
	CallbackScan          func(dest ...any) error
	CallbackMapScan       func(dest map[string]interface{}) error
	CallbackSliceScan     func() ([]interface{}, error)
	CallbackStructScan    func(dest interface{}) error
}

RowsMock is a mock implementation of the sql.Rows interface

func (*RowsMock) Close added in v0.1.8

func (rm *RowsMock) Close() error

Close closes the RowsMock. If CallbackClose is set, it will be called and its return value will be returned. Otherwise, it returns the Error field of RowsMock.

func (*RowsMock) ColumnTypes added in v0.1.8

func (rm *RowsMock) ColumnTypes() ([]*sql.ColumnType, error)

ColumnTypes returns the column types of the RowsMock. If CallbackColumnTypes is set, it will be called and its return value will be returned. Otherwise, it returns an empty slice of *sql.ColumnType and the Error field of RowsMock.

func (*RowsMock) Columns added in v0.1.8

func (rm *RowsMock) Columns() ([]string, error)

Columns returns the column names of the RowsMock. If CallbackColumns is set, it will be called and its return value will be returned. Otherwise, it returns an empty slice of strings and the Error field of RowsMock.

func (*RowsMock) Err added in v0.1.8

func (rm *RowsMock) Err() error

Err returns the error of the RowsMock. If CallbackErr is set, it will be called and its return value will be returned. Otherwise, it returns the Error field of RowsMock.

func (*RowsMock) MapScan added in v0.1.8

func (rm *RowsMock) MapScan(dest map[string]interface{}) error

MapScan scans the current row of the RowsMock into the provided map. If CallbackMapScan is set, it will be called with the map and its return value will be returned. Otherwise, it returns the Error field of RowsMock.

func (*RowsMock) Next added in v0.1.8

func (rm *RowsMock) Next() bool

Next returns true if there is another row in the RowsMock, false otherwise. If CallbackNext is set, it will be called and its return value will be returned. Otherwise, it returns false.

func (*RowsMock) NextResultSet added in v0.1.8

func (rm *RowsMock) NextResultSet() bool

NextResultSet returns true if there is another result set in the RowsMock, false otherwise. If CallbackNextResultSet is set, it will be called and its return value will be returned. Otherwise, it returns false.

func (*RowsMock) Scan added in v0.1.8

func (rm *RowsMock) Scan(dest ...any) error

Scan scans the current row of the RowsMock into the provided destination values. If CallbackScan is set, it will be called with the destination values and its return value will be returned. Otherwise, it returns the Error field of RowsMock.

func (*RowsMock) SliceScan added in v0.1.8

func (rm *RowsMock) SliceScan() ([]interface{}, error)

SliceScan scans the current row of the RowsMock into a slice of interface{} values. If CallbackSliceScan is set, it will be called and its return value will be returned. Otherwise, it returns an empty slice of interface{} and the Error field of RowsMock.

func (*RowsMock) StructScan added in v0.1.8

func (rm *RowsMock) StructScan(dest interface{}) error

StructScan scans the current row of the RowsMock into the provided struct. If CallbackStructScan is set, it will be called with the struct and its return value will be returned. Otherwise, it returns the Error field of RowsMock.

type Stmt added in v0.1.8

type Stmt interface {

	// Close closes the statement.
	Close() error
	// Exec executes a prepared statement with the given arguments and
	// returns a Result summarizing the effect of the statement.
	// Exec uses context.Background internally; to specify the context, use
	// ExecContext.
	Exec(args ...any) (sql.Result, error)
	// ExecContext executes a prepared statement with the given arguments and
	// returns a Result summarizing the effect of the statement.
	ExecContext(ctx context.Context, args ...any) (sql.Result, error)

	// Get using the prepared statement.
	// Any placeholder parameters are replaced with supplied args.
	// An error is returned if the result set is empty.
	Get(dest interface{}, args ...interface{}) error
	// GetContext using the prepared statement.
	// Any placeholder parameters are replaced with supplied args.
	// An error is returned if the result set is empty.
	GetContext(ctx context.Context, dest interface{}, args ...interface{}) error
	// MustExec (panic) using this statement. Note that the query portion of the error
	// output will be blank, as Stmt does not expose its query.
	// Any placeholder parameters are replaced with supplied args.
	MustExec(args ...interface{}) sql.Result
	// MustExecContext (panic) using this statement. Note that the query portion of
	// the error output will be blank, as Stmt does not expose its query.
	// Any placeholder parameters are replaced with supplied args.
	MustExecContext(ctx context.Context, args ...interface{}) sql.Result
	// QueryRow using this statement.
	// Any placeholder parameters are replaced with supplied args.
	QueryRow(args ...interface{}) Row
	// QueryRowContext using this statement.
	// Any placeholder parameters are replaced with supplied args.
	QueryRowContext(ctx context.Context, args ...interface{}) Row
	// Query using this statement.
	// Any placeholder parameters are replaced with supplied args.
	Query(args ...interface{}) (Rows, error)
	// QueryContext using this statement.
	// Any placeholder parameters are replaced with supplied args.
	QueryContext(ctx context.Context, args ...interface{}) (Rows, error)
	// Select using the prepared statement.
	// Any placeholder parameters are replaced with supplied args.
	Select(dest interface{}, args ...interface{}) error
	// SelectContext using the prepared statement.
	// Any placeholder parameters are replaced with supplied args.
	SelectContext(ctx context.Context, dest interface{}, args ...interface{}) error
	// Unsafe returns a version of Stmt which will silently succeed to scan when
	// columns in the SQL result have no fields in the destination struct.
	Unsafe() *sqlx.Stmt
	// Safe returns the underlying Stmt
	Safe() *sqlx.Stmt
}

Stmt defines a new statement

type StmtMock added in v0.1.8

type StmtMock struct {
	Error                   error
	CallbackClose           func() error
	CallbackExec            func(args ...any) (sql.Result, error)
	CallbackExecContext     func(ctx context.Context, args ...any) (sql.Result, error)
	CallbackGet             func(dest interface{}, args ...interface{}) error
	CallbackGetContext      func(ctx context.Context, dest interface{}, args ...interface{}) error
	CallbackMustExec        func(args ...interface{}) sql.Result
	CallbackMustExecContext func(ctx context.Context, args ...interface{}) sql.Result
	CallbackQueryRow        func(args ...interface{}) Row
	CallbackQueryRowContext func(ctx context.Context, args ...interface{}) Row
	CallbackQuery           func(args ...interface{}) (Rows, error)
	CallbackQueryContext    func(ctx context.Context, args ...interface{}) (Rows, error)
	CallbackSelect          func(dest interface{}, args ...interface{}) error
	CallbackSelectContext   func(ctx context.Context, dest interface{}, args ...interface{}) error
	CallbackUnsafe          func() *sqlx.Stmt
	CallbackSafe            func() *sqlx.Stmt
}

StmtMock is a mock implementation of the sqlx.Stmt interface

func (*StmtMock) Close added in v0.1.8

func (sm *StmtMock) Close() error

Close is a mock implementation of the Close method of sqlx.Stmt interface. It calls the CallbackClose function if it is not nil, otherwise it returns the Error field.

func (*StmtMock) Exec added in v0.1.8

func (sm *StmtMock) Exec(args ...any) (sql.Result, error)

Exec is a mock implementation of the Exec method of sqlx.Stmt interface. It calls the CallbackExec function if it is not nil, otherwise it returns a ResultMock and the Error field.

func (*StmtMock) ExecContext added in v0.1.8

func (sm *StmtMock) ExecContext(ctx context.Context, args ...any) (sql.Result, error)

ExecContext is a mock implementation of the ExecContext method of sqlx.Stmt interface. It calls the CallbackExecContext function if it is not nil, otherwise it returns a ResultMock and the Error field.

func (*StmtMock) Get added in v0.1.8

func (sm *StmtMock) Get(dest interface{}, args ...interface{}) error

Get is a mock implementation of the Get method of sqlx.Stmt interface. It calls the CallbackGet function if it is not nil, otherwise it returns the Error field.

func (*StmtMock) GetContext added in v0.1.8

func (sm *StmtMock) GetContext(ctx context.Context, dest interface{}, args ...interface{}) error

GetContext is a mock implementation of the GetContext method of sqlx.Stmt interface. It calls the CallbackGetContext function if it is not nil, otherwise it returns the Error field.

func (*StmtMock) MustExec added in v0.1.8

func (sm *StmtMock) MustExec(args ...interface{}) sql.Result

MustExec is a mock implementation of the MustExec method of sqlx.Stmt interface. It calls the CallbackMustExec function if it is not nil, otherwise it returns a ResultMock.

func (*StmtMock) MustExecContext added in v0.1.8

func (sm *StmtMock) MustExecContext(ctx context.Context, args ...interface{}) sql.Result

MustExecContext is a mock implementation of the MustExecContext method of sqlx.Stmt interface. It calls the CallbackMustExecContext function if it is not nil, otherwise it returns a ResultMock.

func (*StmtMock) Query added in v0.1.8

func (sm *StmtMock) Query(args ...interface{}) (Rows, error)

Query is a mock implementation of the Query method of sqlx.Stmt interface. It calls the CallbackQuery function if it is not nil, otherwise it returns a RowsMock and the Error field.

func (*StmtMock) QueryContext added in v0.1.8

func (sm *StmtMock) QueryContext(ctx context.Context, args ...interface{}) (Rows, error)

QueryContext is a mock implementation of the QueryContext method of sqlx.Stmt interface. It calls the CallbackQueryContext function if it is not nil, otherwise it returns a RowsMock and the Error field.

func (*StmtMock) QueryRow added in v0.1.8

func (sm *StmtMock) QueryRow(args ...interface{}) Row

QueryRow is a mock implementation of the QueryRow method of sqlx.Stmt interface. It calls the CallbackQueryRow function if it is not nil, otherwise it returns a RowMock.

func (*StmtMock) QueryRowContext added in v0.1.8

func (sm *StmtMock) QueryRowContext(ctx context.Context, args ...interface{}) Row

QueryRowContext is a mock implementation of the QueryRowContext method of sqlx.Stmt interface. It calls the CallbackQueryRowContext function if it is not nil, otherwise it returns a RowMock.

func (*StmtMock) Safe added in v0.1.8

func (sm *StmtMock) Safe() *sqlx.Stmt

Safe is a mock implementation of the Safe method of sqlx.Stmt interface. It calls the CallbackSafe function if it is not nil, otherwise it returns a sqlx.Stmt.

func (*StmtMock) Select added in v0.1.8

func (sm *StmtMock) Select(dest interface{}, args ...interface{}) error

Select is a mock implementation of the Select method of sqlx.Stmt interface. It calls the CallbackSelect function if it is not nil, otherwise it returns the Error field.

func (*StmtMock) SelectContext added in v0.1.8

func (sm *StmtMock) SelectContext(ctx context.Context, dest interface{}, args ...interface{}) error

SelectContext is a mock implementation of the SelectContext method of sqlx.Stmt interface. It calls the CallbackSelectContext function if it is not nil, otherwise it returns the Error field.

func (*StmtMock) Unsafe added in v0.1.8

func (sm *StmtMock) Unsafe() *sqlx.Stmt

Unsafe is a mock implementation of the Unsafe method of sqlx.Stmt interface. It calls the CallbackUnsafe function if it is not nil, otherwise it returns a sqlx.Stmt.

type Tx added in v0.1.8

type Tx interface {

	// Commit commits the transaction.
	Commit() error
	// Exec executes a query that doesn't return rows.
	// For example: an INSERT and UPDATE.
	//
	// Exec uses context.Background internally; to specify the context, use
	// ExecContext.
	Exec(query string, args ...any) (sql.Result, error)
	// ExecContext executes a query that doesn't return rows.
	// For example: an INSERT and UPDATE.
	ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
	// Rollback aborts the transaction.
	Rollback() error

	// BindNamed binds a query within a transaction's bindvar type.
	BindNamed(query string, arg interface{}) (string, []interface{}, error)
	// DriverName returns the driverName used by the DB which began this transaction.
	DriverName() string
	// Get within a transaction.
	// Any placeholder parameters are replaced with supplied args.
	// An error is returned if the result set is empty.
	Get(dest interface{}, query string, args ...interface{}) error
	// GetContext within a transaction and context.
	// Any placeholder parameters are replaced with supplied args.
	// An error is returned if the result set is empty.
	GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
	// MustExec runs MustExec within a transaction.
	// Any placeholder parameters are replaced with supplied args.
	MustExec(query string, args ...interface{}) sql.Result
	// MustExecContext runs MustExecContext within a transaction.
	// Any placeholder parameters are replaced with supplied args.
	MustExecContext(ctx context.Context, query string, args ...interface{}) sql.Result
	// NamedExec a named query within a transaction.
	// Any named placeholder parameters are replaced with fields from arg.
	NamedExec(query string, arg interface{}) (sql.Result, error)
	// NamedExecContext using this Tx.
	// Any named placeholder parameters are replaced with fields from arg.
	NamedExecContext(ctx context.Context, query string, arg interface{}) (sql.Result, error)
	// NamedQuery within a transaction.
	// Any named placeholder parameters are replaced with fields from arg.
	NamedQuery(query string, arg interface{}) (Rows, error)
	// NamedStmt returns a version of the prepared statement which runs within a transaction.
	NamedStmt(stmt NamedStmt) NamedStmt
	// NamedStmtContext returns a version of the prepared statement which runs
	// within a transaction.
	NamedStmtContext(ctx context.Context, stmt NamedStmt) NamedStmt
	// PrepareNamed returns an NamedStmt
	PrepareNamed(query string) (NamedStmt, error)
	// PrepareNamedContext returns an NamedStmt
	PrepareNamedContext(ctx context.Context, query string) (NamedStmt, error)
	// Prepare  a statement within a transaction.
	Prepare(query string) (Stmt, error)
	// PrepareContext returns an godb.Stmt instead of a sql.Stmt.
	//
	// The provided context is used for the preparation of the statement, not for
	// the execution of the statement.
	PrepareContext(ctx context.Context, query string) (Stmt, error)
	// QueryRow within a transaction.
	// Any placeholder parameters are replaced with supplied args.
	QueryRow(query string, args ...interface{}) Row
	// QueryRowContext within a transaction and context.
	// Any placeholder parameters are replaced with supplied args.
	QueryRowContext(ctx context.Context, query string, args ...interface{}) Row
	// Query within a transaction.
	// Any placeholder parameters are replaced with supplied args.
	Query(query string, args ...interface{}) (Rows, error)
	// QueryContext within a transaction and context.
	// Any placeholder parameters are replaced with supplied args.
	QueryContext(ctx context.Context, query string, args ...interface{}) (Rows, error)
	// Rebind a query within a transaction's bindvar type.
	Rebind(query string) string
	// Select within a transaction.
	// Any placeholder parameters are replaced with supplied args.
	Select(dest interface{}, query string, args ...interface{}) error
	// SelectContext within a transaction and context.
	// Any placeholder parameters are replaced with supplied args.
	SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
	// Stmt returns a version of the prepared statement which runs within a transaction.  Provided
	// stmt can be either *sql.Stmt or *sqlx.Stmt.
	Stmt(stmt interface{}) Stmt
	// StmtContext returns a version of the prepared statement which runs within a
	// transaction. Provided stmt can be either *sql.Stmt or *sqlx.Stmt.
	StmtContext(ctx context.Context, stmt interface{}) Stmt
	// Unsafe returns a version of Tx which will silently succeed to scan when
	// columns in the SQL result have no fields in the destination struct.
	Unsafe() *sqlx.Tx
	// Safe returns the underlying Tx
	Safe() *sqlx.Tx
}

Tx defines a new transaction interface

type TxMock added in v0.1.8

type TxMock struct {
	Error                       error
	CallbackCommit              func() error
	CallbackExec                func(query string, args ...any) (sql.Result, error)
	CallbackExecContext         func(ctx context.Context, query string, args ...any) (sql.Result, error)
	CallbackRollback            func() error
	CallbackBindNamed           func(query string, arg interface{}) (string, []interface{}, error)
	CallbackDriverName          func() string
	CallbackGet                 func(dest interface{}, query string, args ...interface{}) error
	CallbackGetContext          func(ctx context.Context, dest interface{}, query string, args ...interface{}) error
	CallbackMustExec            func(query string, args ...interface{}) sql.Result
	CallbackMustExecContext     func(ctx context.Context, query string, args ...interface{}) sql.Result
	CallbackNamedExec           func(query string, arg interface{}) (sql.Result, error)
	CallbackNamedExecContext    func(ctx context.Context, query string, arg interface{}) (sql.Result, error)
	CallbackNamedQuery          func(query string, arg interface{}) (Rows, error)
	CallbackNamedStmt           func(stmt NamedStmt) NamedStmt
	CallbackNamedStmtContext    func(ctx context.Context, stmt NamedStmt) NamedStmt
	CallbackPrepareNamed        func(query string) (NamedStmt, error)
	CallbackPrepareNamedContext func(ctx context.Context, query string) (NamedStmt, error)
	CallbackPrepare             func(query string) (Stmt, error)
	CallbackPrepareContext      func(ctx context.Context, query string) (Stmt, error)
	CallbackQueryRow            func(query string, args ...interface{}) Row
	CallbackQueryRowContext     func(ctx context.Context, query string, args ...interface{}) Row
	CallbackQuery               func(query string, args ...interface{}) (Rows, error)
	CallbackQueryContext        func(ctx context.Context, query string, args ...interface{}) (Rows, error)
	CallbackRebind              func(query string) string
	CallbackSelect              func(dest interface{}, query string, args ...interface{}) error
	CallbackSelectContext       func(ctx context.Context, dest interface{}, query string, args ...interface{}) error
	CallbackStmt                func(stmt interface{}) Stmt
	CallbackStmtContext         func(ctx context.Context, stmt interface{}) Stmt
	CallbackUnsafe              func() *sqlx.Tx
	CallbackSafe                func() *sqlx.Tx
}

TxMock is a mock implementation of the sqlx.Tx interface

func (*TxMock) BindNamed added in v0.1.8

func (tm *TxMock) BindNamed(query string, arg interface{}) (string, []interface{}, error)

BindNamed binds named parameters in a query. If a callback function is set for BindNamed, it will be called instead of the default implementation. Returns the modified query string, a slice of interface{} containing the bound values, and an error if the callback function returns these values or if an error is set in the TxMock struct.

func (*TxMock) Commit added in v0.1.8

func (tm *TxMock) Commit() error

Commit commits the transaction. If a callback function is set for Commit, it will be called instead of the default implementation. Returns an error if the callback function returns an error or if an error is set in the TxMock struct.

func (*TxMock) DriverName added in v0.1.8

func (tm *TxMock) DriverName() string

DriverName returns the name of the driver. If a callback function is set for DriverName, it will be called instead of the default implementation. Returns the driver name or an empty string if the callback function returns a driver name or if no callback function is set.

func (*TxMock) Exec added in v0.1.8

func (tm *TxMock) Exec(query string, args ...any) (sql.Result, error)

Exec executes a query without returning any rows. If a callback function is set for Exec, it will be called instead of the default implementation. Returns a sql.Result and an error if the callback function returns a result and an error or if an error is set in the TxMock struct.

func (*TxMock) ExecContext added in v0.1.8

func (tm *TxMock) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)

ExecContext executes a query without returning any rows with a context. If a callback function is set for ExecContext, it will be called instead of the default implementation. Returns a sql.Result and an error if the callback function returns a result and an error or if an error is set in the TxMock struct.

func (*TxMock) Get added in v0.1.8

func (tm *TxMock) Get(dest interface{}, query string, args ...interface{}) error

Get retrieves a single row from the database and stores the result in the provided struct or pointer. If a callback function is set for Get, it will be called instead of the default implementation. Returns an error if the callback function returns an error or if an error is set in the TxMock struct.

func (*TxMock) GetContext added in v0.1.8

func (tm *TxMock) GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error

GetContext retrieves a single row from the database with a context and stores the result in the provided struct or pointer. If a callback function is set for GetContext, it will be called instead of the default implementation. Returns an error if the callback function returns an error or if an error is set in the TxMock struct.

func (*TxMock) MustExec added in v0.1.8

func (tm *TxMock) MustExec(query string, args ...interface{}) sql.Result

MustExec executes a query without returning any rows and panics if an error occurs. If a callback function is set for MustExec, it will be called instead of the default implementation. Returns a sql.Result or a ResultMock if the callback function returns a result or if no callback function is set.

func (*TxMock) MustExecContext added in v0.1.8

func (tm *TxMock) MustExecContext(ctx context.Context, query string, args ...interface{}) sql.Result

MustExecContext executes a query without returning any rows with a context and panics if an error occurs. If a callback function is set for MustExecContext, it will be called instead of the default implementation. Returns a sql.Result or a ResultMock if the callback function returns a result or if no callback function is set.

func (*TxMock) NamedExec added in v0.1.8

func (tm *TxMock) NamedExec(query string, arg interface{}) (sql.Result, error)

NamedExec executes a named query without returning any rows. If a callback function is set for NamedExec, it will be called instead of the default implementation. Returns a sql.Result and an error if the callback function returns a result and an error or if an error is set in the TxMock struct.

func (*TxMock) NamedExecContext added in v0.1.8

func (tm *TxMock) NamedExecContext(ctx context.Context, query string, arg interface{}) (sql.Result, error)

NamedExecContext executes a named query without returning any rows with a context. If a callback function is set for NamedExecContext, it will be called instead of the default implementation. Returns a sql.Result and an error if the callback function returns a result and an error or if an error is set in the TxMock struct.

func (*TxMock) NamedQuery added in v0.1.8

func (tm *TxMock) NamedQuery(query string, arg interface{}) (Rows, error)

NamedQuery executes a named query that returns rows. If a callback function is set for NamedQuery, it will be called instead of the default implementation. Returns a Rows and an error if the callback function returns rows and an error or if an error is set in the TxMock struct.

func (*TxMock) NamedStmt added in v0.1.8

func (tm *TxMock) NamedStmt(stmt NamedStmt) NamedStmt

NamedStmt returns a NamedStmt for the provided NamedStmt. If a callback function is set for NamedStmt, it will be called instead of the default implementation. Returns a NamedStmt or a NamedStmtMock if the callback function returns a NamedStmt or if no callback function is set.

func (*TxMock) NamedStmtContext added in v0.1.8

func (tm *TxMock) NamedStmtContext(ctx context.Context, stmt NamedStmt) NamedStmt

NamedStmtContext returns a NamedStmt for the provided NamedStmt with a context. If a callback function is set for NamedStmtContext, it will be called instead of the default implementation. Returns a NamedStmt or a NamedStmtMock if the callback function returns a NamedStmt or if no callback function is set.

func (*TxMock) Prepare added in v0.1.8

func (tm *TxMock) Prepare(query string) (Stmt, error)

Prepare prepares a statement for execution. If a callback function is set for Prepare, it will be called instead of the default implementation. Returns a Stmt and an error if the callback function returns a Stmt and an error or if an error is set in the TxMock struct.

func (*TxMock) PrepareContext added in v0.1.8

func (tm *TxMock) PrepareContext(ctx context.Context, query string) (Stmt, error)

PrepareContext prepares a statement for execution with a context. If a callback function is set for PrepareContext, it will be called instead of the default implementation. Returns a Stmt and an error if the callback function returns a Stmt and an error or if an error is set in the TxMock struct.

func (*TxMock) PrepareNamed added in v0.1.8

func (tm *TxMock) PrepareNamed(query string) (NamedStmt, error)

PrepareNamed prepares a named statement for execution. If a callback function is set for PrepareNamed, it will be called instead of the default implementation. Returns a NamedStmt and an error if the callback function returns a NamedStmt and an error or if an error is set in the TxMock struct.

func (*TxMock) PrepareNamedContext added in v0.1.8

func (tm *TxMock) PrepareNamedContext(ctx context.Context, query string) (NamedStmt, error)

PrepareNamedContext prepares a named statement for execution with a context. If a callback function is set for PrepareNamedContext, it will be called instead of the default implementation. Returns a NamedStmt and an error if the callback function returns a NamedStmt and an error or if an error is set in the TxMock struct.

func (*TxMock) Query added in v0.1.8

func (tm *TxMock) Query(query string, args ...interface{}) (Rows, error)

Query executes a query that returns rows. If a callback function is set for Query, it will be called instead of the default implementation. Returns a Rows and an error if the callback function returns rows and an error or if an error is set in the TxMock struct.

func (*TxMock) QueryContext added in v0.1.8

func (tm *TxMock) QueryContext(ctx context.Context, query string, args ...interface{}) (Rows, error)

QueryContext executes a query that returns rows with a context. If a callback function is set for QueryContext, it will be called instead of the default implementation. Returns a Rows and an error if the callback function returns rows and an error or if an error is set in the TxMock struct.

func (*TxMock) QueryRow added in v0.1.8

func (tm *TxMock) QueryRow(query string, args ...interface{}) Row

QueryRow executes a query that is expected to return at most one row. If a callback function is set for QueryRow, it will be called instead of the default implementation. Returns a Row or a RowMock if the callback function returns a Row or if no callback function is set.

func (*TxMock) QueryRowContext added in v0.1.8

func (tm *TxMock) QueryRowContext(ctx context.Context, query string, args ...interface{}) Row

QueryRowContext executes a query that is expected to return at most one row with a context. If a callback function is set for QueryRowContext, it will be called instead of the default implementation. Returns a Row or a RowMock if the callback function returns a Row or if no callback function is set.

func (*TxMock) Rebind added in v0.1.8

func (tm *TxMock) Rebind(query string) string

Rebind returns a query with the placeholders replaced with the appropriate bindvar for the database. If a callback function is set for Rebind, it will be called instead of the default implementation. Returns the modified query string or an empty string if the callback function returns a modified query or if no callback function is set.

func (*TxMock) Rollback added in v0.1.8

func (tm *TxMock) Rollback() error

Rollback rolls back the transaction. If a callback function is set for Rollback, it will be called instead of the default implementation. Returns an error if the callback function returns an error or if an error is set in the TxMock struct.

func (*TxMock) Safe added in v0.1.8

func (tm *TxMock) Safe() *sqlx.Tx

Safe returns the underlying *sqlx.Tx. If a callback function is set for Safe, it will be called instead of the default implementation. Returns the underlying *sqlx.Tx or a new *sqlx.Tx if the callback function returns a *sqlx.Tx or if no callback function is set.

func (*TxMock) Select added in v0.1.8

func (tm *TxMock) Select(dest interface{}, query string, args ...interface{}) error

Select executes a query that returns multiple rows and stores the result in the provided slice or struct. If a callback function is set for Select, it will be called instead of the default implementation. Returns an error if the callback function returns an error or if an error is set in the TxMock struct.

func (*TxMock) SelectContext added in v0.1.8

func (tm *TxMock) SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error

SelectContext executes a query that returns multiple rows with a context and stores the result in the provided slice or struct. If a callback function is set for SelectContext, it will be called instead of the default implementation. Returns an error if the callback function returns an error or if an error is set in the TxMock struct.

func (*TxMock) Stmt added in v0.1.8

func (tm *TxMock) Stmt(stmt interface{}) Stmt

Stmt returns a Stmt for the provided Stmt. If a callback function is set for Stmt, it will be called instead of the default implementation. Returns a Stmt or a StatementMock if the callback function returns a Stmt or if no callback function is set.

func (*TxMock) StmtContext added in v0.1.8

func (tm *TxMock) StmtContext(ctx context.Context, stmt interface{}) Stmt

StmtContext returns a Stmt for the provided Stmt with a context. If a callback function is set for StmtContext, it will be called instead of the default implementation. Returns a Stmt or a StatementMock if the callback function returns a Stmt or if no callback function is set.

func (*TxMock) Unsafe added in v0.1.8

func (tm *TxMock) Unsafe() *sqlx.Tx

Unsafe returns the underlying *sqlx.Tx. If a callback function is set for Unsafe, it will be called instead of the default implementation. Returns the underlying *sqlx.Tx or a new *sqlx.Tx if the callback function returns a *sqlx.Tx or if no callback function is set.

Jump to

Keyboard shortcuts

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