Documentation ¶
Overview ¶
Package sql implements the standard SQL database interface.
Index ¶
- Variables
- type Cursor
- type DB
- type MockCursor
- type MockDB
- type MockQueryer
- func (m *MockQueryer) Cursor(ctx context.Context, stmt SQL, args ...interface{}) Cursor
- func (m *MockQueryer) Exec(ctx context.Context, stmt SQL, args ...interface{}) (Result, error)
- func (m *MockQueryer) QueryMany(ctx context.Context, dst interface{}, stmt SQL, args ...interface{}) error
- func (m *MockQueryer) QueryOne(ctx context.Context, dst interface{}, stmt SQL, args ...interface{}) error
- type MockTxer
- type Queryer
- type Result
- type SQL
- type Txer
Constants ¶
This section is empty.
Variables ¶
var ErrNoRows = sql.ErrNoRows
ErrNoRows indicate that a QueryOne returned no row.
Functions ¶
This section is empty.
Types ¶
type Cursor ¶
Cursor implement an efficient, iterable database result. Typical usage is to use an inifinite for loop and exit when Next returns false. It must be closed after use. Consult Err to find any error that may have caused early exit from the loop.
type DB ¶
type DB interface { Queryer Begin(context.Context) (Txer, error) BeginFunc(context.Context, func(Txer) error) error Close() error }
DB defines the method required for a database pool.
type MockCursor ¶
type MockCursor struct { CloseFunc func() error ErrFunc func() error NextFunc func() bool ScanFunc func(interface{}) error }
MockCursor is a test mock for the Cursor interface.
func (*MockCursor) Close ¶
func (m *MockCursor) Close() error
func (*MockCursor) Err ¶
func (m *MockCursor) Err() error
func (*MockCursor) Next ¶
func (m *MockCursor) Next() bool
func (*MockCursor) Scan ¶
func (m *MockCursor) Scan(dst interface{}) error
type MockDB ¶
type MockDB struct { Queryer BeginFn func(context.Context) (Txer, error) BeginFuncFn func(context.Context, func(Txer) error) error CloseFn func() error }
MockDB is a test mock for the DB interface.
type MockQueryer ¶
type MockQueryer struct { ExecFunc func(context.Context, SQL, ...interface{}) (Result, error) QueryOneFunc func(context.Context, interface{}, SQL, ...interface{}) error QueryManyFunc func(context.Context, interface{}, SQL, ...interface{}) error CursorFunc func(context.Context, SQL, ...interface{}) Cursor }
MockQueryer is a test mock for the Queryer interface.
func (*MockQueryer) Cursor ¶
func (m *MockQueryer) Cursor(ctx context.Context, stmt SQL, args ...interface{}) Cursor
type MockTxer ¶
type MockTxer struct { Queryer CommitFunc func(context.Context) error RollbackFunc func(context.Context) error }
MockTxer is a test mock for the Txer interface.
type Queryer ¶
type Queryer interface { Exec(context.Context, SQL, ...interface{}) (Result, error) QueryOne(context.Context, interface{}, SQL, ...interface{}) error QueryMany(context.Context, interface{}, SQL, ...interface{}) error Cursor(context.Context, SQL, ...interface{}) Cursor }
Queryer is the common interface to query and execute SQL statements.
type SQL ¶
type SQL string
SQL is a distinct type for SQL statements to prevent accidental SQL injection by directly manipulating or concatenating strings.
type Txer ¶
Txer is a database transaction. It implements Queryer, and adds methods to Commit or Rollback the transaction. Calling Rollback on a committed transaction returns an error and is otherwise a no-op, so a useful idiom is to defer a call to Rollback after starting a transaction, and call Commit when needed, which will invalidate the Rollback.