Documentation
¶
Overview ¶
Package sqladapter adapts a database/sql pool to the core store interfaces. It is shared by the providers built on database/sql drivers.
Index ¶
- func Each(ctx context.Context, db *sql.DB, query string, args []any, ...) error
- type Base
- type ClassifyFunc
- type Pool
- func (d *Pool) BeginTx(ctx context.Context, opts *store.TxOptions) (store.Tx, error)
- func (d *Pool) Close() error
- func (d *Pool) DB() *sql.DB
- func (d *Pool) ExecContext(ctx context.Context, query string, args ...any) (store.Result, error)
- func (d *Pool) PrepareContext(ctx context.Context, query string) (store.Prepared, error)
- func (d *Pool) QueryContext(ctx context.Context, query string, args ...any) (store.Rows, error)
- type RowsFunc
- type Scanned
- type TableKey
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Base ¶ added in v0.1.13
type Base struct {
*Pool
// contains filtered or unexported fields
}
Base is what the providers on database/sql share: the pool and the dialect, EXPLAIN estimator and schema introspector of one database. A provider embeds it and adds what is its own.
func NewBase ¶ added in v0.1.13
func NewBase(pool *Pool, d dialect.Dialect, e cost.Explainer, i introspect.Introspector) Base
NewBase is a Base on pool with the given adapters.
func (Base) Introspector ¶ added in v0.1.13
func (b Base) Introspector() introspect.Introspector
Introspector returns the schema introspector.
type ClassifyFunc ¶
ClassifyFunc turns a driver error into a store error the gateway acts on (such as *store.ConstraintError), or returns it unchanged.
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool wraps *sql.DB, satisfying store.DB, store.Preparer and store.TxBeginner. Embedders get DB(), which bootstrap uses to size the pool and ping it; the type is not named DB so an embedded field cannot shadow that method.
func New ¶
func New(db *sql.DB, rows RowsFunc, classify ClassifyFunc) *Pool
New wraps db. A nil rows returns the driver rows unchanged; a nil classify leaves errors unchanged. Statement errors and errors met while reading rows (where PostgreSQL reports a failed INSERT ... RETURNING) are classified.
func (*Pool) ExecContext ¶
ExecContext implements store.DB.
func (*Pool) PrepareContext ¶
PrepareContext implements store.Preparer.
type Scanned ¶ added in v0.1.13
type Scanned struct {
Attrs map[TableKey][]entity.Attribute
Keys map[TableKey][]entity.Key
Indexes map[TableKey][]entity.Index
FKs map[TableKey][]entity.ForeignKey
Cascades map[TableKey][]entity.Cascade
SideEffects map[TableKey]bool
}
Scanned is the metadata of the scanned schemas, by relation, as the queries of a scan fill it: each reads one kind of metadata of every relation at once, the way mysqldump reads a database, so the round trips do not grow with the relations. The Scan methods read the rows the providers' queries have in common.
func (*Scanned) Fill ¶ added in v0.1.13
Fill sets on e what the scan found of k: its columns, keys, indexes, foreign keys, cascades and write effects.
func (*Scanned) ScanColumn ¶ added in v0.1.13
ScanColumn reads a row of a columns query selecting, in order, the schema, relation, column, type, nullability (YES or NO), comment, and whether the database supplies a value, computes it and takes it from a sequence; the rows come in column order.
func (*Scanned) ScanForeignKeyColumn ¶ added in v0.1.13
ScanForeignKeyColumn reads a row of a foreign keys query selecting, in key order, the schema, relation, constraint, column, referenced schema, relation and column, and the delete and update rules, which actions maps to the entity's (a rule it leaves out only checks).