sql

package
v0.0.0-...-e1e9d1d Latest Latest
Warning

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

Go to latest
Published: May 20, 2021 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Overview

Package sql implements the standard SQL database interface.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoRows = sql.ErrNoRows

ErrNoRows indicate that a QueryOne returned no row.

Functions

This section is empty.

Types

type Cursor

type Cursor interface {
	Close() error
	Err() error
	Next() bool
	Scan(interface{}) error
}

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.

func (*MockDB) Begin

func (m *MockDB) Begin(ctx context.Context) (Txer, error)

func (*MockDB) BeginFunc

func (m *MockDB) BeginFunc(ctx context.Context, fn func(Txer) error) error

func (*MockDB) Close

func (m *MockDB) Close() error

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

func (*MockQueryer) Exec

func (m *MockQueryer) Exec(ctx context.Context, stmt SQL, args ...interface{}) (Result, error)

func (*MockQueryer) QueryMany

func (m *MockQueryer) QueryMany(ctx context.Context, dst interface{}, stmt SQL, args ...interface{}) error

func (*MockQueryer) QueryOne

func (m *MockQueryer) QueryOne(ctx context.Context, dst interface{}, stmt SQL, args ...interface{}) error

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.

func (*MockTxer) Commit

func (m *MockTxer) Commit(ctx context.Context) error

func (*MockTxer) Rollback

func (m *MockTxer) Rollback(ctx context.Context) error

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 Result

type Result = sql.Result

Result summarizes an executed SQL command.

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

type Txer interface {
	Queryer
	Commit(context.Context) error
	Rollback(context.Context) error
}

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.

Jump to

Keyboard shortcuts

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