mockconn

package
v0.0.0-...-ab31a86 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultArgFmt = "$%d"
View Source
var ErrMockedScan = errors.New("mocked scan")

Functions

func New

func New(ctx context.Context, queryWriter io.Writer, rowsProvider RowsProvider) sqldb.Connection

Types

type OneTimeRowsProvider

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

func NewOneTimeRowsProvider

func NewOneTimeRowsProvider() *OneTimeRowsProvider

func (*OneTimeRowsProvider) AddRowScannerQuery

func (p *OneTimeRowsProvider) AddRowScannerQuery(scanner sqldb.RowScanner, query string, args ...any)

func (*OneTimeRowsProvider) AddRowsScannerQuery

func (p *OneTimeRowsProvider) AddRowsScannerQuery(scanner sqldb.RowsScanner, query string, args ...any)

func (*OneTimeRowsProvider) QueryRow

func (p *OneTimeRowsProvider) QueryRow(structFieldNamer sqldb.StructFieldMapper, query string, args ...any) sqldb.RowScanner

func (*OneTimeRowsProvider) QueryRows

func (p *OneTimeRowsProvider) QueryRows(structFieldNamer sqldb.StructFieldMapper, query string, args ...any) sqldb.RowsScanner

type Row

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

Row implements impl.Row with the fields of a struct as column values.

func NewRow

func NewRow(rowStruct any, columnNamer sqldb.StructFieldMapper) *Row

func (*Row) Columns

func (r *Row) Columns() ([]string, error)

func (*Row) Scan

func (r *Row) Scan(dest ...any) error

func (*Row) StructFieldMapper

func (r *Row) StructFieldMapper() sqldb.StructFieldMapper

type Rows

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

func NewRows

func NewRows(rows ...*Row) *Rows

func NewRowsFromStructs

func NewRowsFromStructs(rowStructs any, columnNamer sqldb.StructFieldMapper) *Rows

func (*Rows) Close

func (r *Rows) Close() error

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.

func (*Rows) Columns

func (r *Rows) Columns() ([]string, error)

Columns returns the column names.

func (*Rows) Err

func (r *Rows) Err() error

Err returns the error, if any, that was encountered during iteration. Err may be called after an explicit or implicit Close.

func (*Rows) Next

func (r *Rows) Next() bool

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.

func (*Rows) Reset

func (r *Rows) Reset()

Reset to the state after NewRows (no error, not closed, before first row).

func (*Rows) Scan

func (r *Rows) Scan(dest ...any) error

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.

type RowsProvider

type RowsProvider interface {
	QueryRow(structFieldNamer sqldb.StructFieldMapper, query string, args ...any) sqldb.RowScanner
	QueryRows(structFieldNamer sqldb.StructFieldMapper, query string, args ...any) sqldb.RowsScanner
}

func NewSingleRowProvider

func NewSingleRowProvider(row *Row) RowsProvider

NewSingleRowProvider a RowsProvider implementation with a single row that will be re-used for every query.

Jump to

Keyboard shortcuts

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