Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrParameterCountMismatch = errors.New("the number of parameters supplied does not match the statement") ErrOptimisticConcurrencyCheckFailed = errors.New("optimistic concurrency check failed") )
var Options singleton
Functions ¶
This section is empty.
Types ¶
type BaseQuery ¶
BaseQuery is a bare-minium, partial implementation of Query. Users are invited to embed it on types that define a Scan method, thus completing the Query implementation.
func (BaseQuery) Parameters ¶
type BaseScript ¶
BaseScript is a bare-minimum implementation of Script.
func (BaseScript) Parameters ¶
func (this BaseScript) Parameters() []any
func (BaseScript) Statements ¶
func (this BaseScript) Statements() string
type Handle ¶
type Handle interface { Execute(context.Context, ...Script) error Populate(context.Context, ...Query) error PopulateRow(context.Context, ...Query) error }
Handle is a high level approach to common database operations, where each operation implements either the Query or Script interface.
type OptimisticConcurrencyCheck ¶
type OptimisticConcurrencyCheck interface {
ExpectedRowsAffected() uint64
}
OptimisticConcurrencyCheck provides an (optional) hook for a type implementing Script to verify whether the total count of all rows affected matches the returned value. If not, an error wrapped with ErrOptimisticConcurrencyCheckFailed will be returned by Handle.Execute().
type Pool ¶
type Pool interface { PrepareContext(ctx context.Context, query string) (*sql.Stmt, error) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error) QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error) QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row }
Pool is a common subset of methods implemented by *sql.DB and *sql.Tx. The name is a nod to that fact that a *sql.DB implements a Pool of connections.
type Query ¶
type Query interface { // Statement returns a string containing a single SQL query. Statement() string // Parameters returns a slice of the parameters to be used in the query. Parameters() []any // Scan specifies a callback to be provided the *sql.Rows for each retrieved record. Scan(Scanner) error }
Query represents a SQL statement that is expected to provide rows as a result. Rows are provided to the Scan method.
type RowsAffected ¶
type RowsAffected interface {
RowsAffected(uint64)
}
RowsAffected provides an (optional) hook for a type implementing Script to receive the number of rows affected by executing a statement provided by a Script. It is called for each statement that doesn't result in an error.
type Script ¶
type Script interface { // Statements returns a string containing 1 or more SQL statements, separated by `;`. // This means that the ';' character should NOT be used within any of the statements. Statements() string // Parameters returns a slice of the parameters to be interleaved across all SQL // returned from Statements(). Parameters() []any }
Script represents SQL statements that aren't expected to provide rows as a result.