Documentation ¶
Overview ¶
Package psql augments database/sql
Index ¶
- Variables
- func ColumnType(typ *sql.ColumnType) (s string)
- func DelFromContext(ctx context.Context, key string) (ok bool)
- func DiscardDB(ctx context.Context)
- func ExecValues(execResult sql.Result, e error) (ID, rows int64, err error)
- func GetDB(ctx context.Context) (db *sql.DB)
- func NewExecResult(execResult sql.Result, e error) (result parl.ExecResult, err error)
- func QueryString(label string, ctx context.Context, dataSource parl.DataSource, query string, ...) (value string, err error)
- func ScanToInt(sqlRow *sql.Row, e error) (value int, err error)
- func ScanToString(sqlRow *sql.Row, e error) (value string, err error)
- func SqlExec(label string, ctx context.Context, dataSource parl.DataSource, query string, ...) (err error)
- func StoreDB(ctx context.Context, db *sql.DB)
- func StoreInContext(ctx context.Context, key string, value interface{}) (ok bool)
- type Context
- type DBMap
- func (d *DBMap) Close() (err error)
- func (d *DBMap) Exec(partition parl.DBPartition, query string, ctx context.Context, args ...any) (execResult parl.ExecResult, err error)
- func (d *DBMap) Query(partition parl.DBPartition, query string, ctx context.Context, args ...any) (sqlRows *sql.Rows, err error)
- func (d *DBMap) QueryInt(partition parl.DBPartition, query string, ctx context.Context, args ...any) (value int, err error)
- func (d *DBMap) QueryRow(partition parl.DBPartition, query string, ctx context.Context, args ...any) (sqlRow *sql.Row, err error)
- func (d *DBMap) QueryString(partition parl.DBPartition, query string, ctx context.Context, args ...any) (value string, err error)
- type ExecResult
- type StatementCache
- type Stmt
- type StmtWrapper
Constants ¶
This section is empty.
Variables ¶
var DBFactory = &dbFactory{}
DBFactory implements parl.DBFactory providing:
- cached database access
- cached prepared statement queries
Functions ¶
func ColumnType ¶ added in v0.4.127
func ColumnType(typ *sql.ColumnType) (s string)
func DelFromContext ¶
DelFromContext removes a value from context. Thread-safe
func ExecValues ¶ added in v0.4.14
ExecValues parses the result from an Exec* method into its values. if LastInsertId or RowsAffected fails, the error is added to err.
func NewExecResult ¶ added in v0.4.14
func QueryString ¶ added in v0.4.26
func ScanToString ¶ added in v0.4.26
func SqlExec ¶ added in v0.4.26
func SqlExec(label string, ctx context.Context, dataSource parl.DataSource, query string, args ...any) (err error)
SqlExec is used when parl.DB is not available, for example to implement the schema function provided to DBFactory.NewDB(). query is an sql statement that does not return any rows. label is used in error messages. SqlExec uses parl.DataSource obtained from DataSourceNamer.DataSource(). Because the cached prepared statements and the partitioning of parl.DB are not available, SqlExec uses any sql.DB method.
Types ¶
type Context ¶
Context is a context.Context with a Value() implementation
func NewContext ¶
NewContext provides a context.Context with a Value() implementation
type DBMap ¶ added in v0.4.14
type DBMap struct {
// contains filtered or unexported fields
}
DBMap provides:
- caching of SQL-implementation-specific database objects
- a cache for prepared statements via methods Exec Query QueryRow QueryString QueryInt
func NewDBMap ¶ added in v0.4.14
func NewDBMap( dsnr parl.DataSourceNamer, schema func(dataSource parl.DataSource, ctx context.Context) (err error), ) (dbMap *DBMap)
NewDBMap returns a database connection and prepared statement cache for dsnr that implements parl.DB
func NewDBMap2 ¶ added in v0.4.127
func NewDBMap2( dsnr parl.DataSourceNamer, schema func(dataSource parl.DataSource, ctx context.Context) (err error), getp *func(dataSourceName parl.DataSourceName, ctx context.Context) (dbStatementCache *StatementCache, err error), ) (dbMap *DBMap)
func (*DBMap) Exec ¶ added in v0.4.14
func (d *DBMap) Exec( partition parl.DBPartition, query string, ctx context.Context, args ...any) (execResult parl.ExecResult, err error)
Exec executes a query not returning any rows
func (*DBMap) Query ¶ added in v0.4.14
func (d *DBMap) Query( partition parl.DBPartition, query string, ctx context.Context, args ...any) (sqlRows *sql.Rows, err error)
Query executes a query returning zero or more rows
func (*DBMap) QueryInt ¶ added in v0.4.14
func (d *DBMap) QueryInt( partition parl.DBPartition, query string, ctx context.Context, args ...any) (value int, err error)
Query executes a query known to return exactly one row and returns its int value
type ExecResult ¶ added in v0.4.14
type ExecResult struct { ID int64 // last insert ID, 0 if none like UPDATE // contains filtered or unexported fields }
ExecResult makes sql.Result printable. sql.Result are obtained by invoking Exec* methods of sql.DB sql.Stmt sql.Conn sql.Tx. sql.Result is an interface with methods LastInsertId and RowsAffected. each driver provides an sql.Result implementation.
func (*ExecResult) Get ¶ added in v0.4.14
func (r *ExecResult) Get() (ID int64, rows int64)
Get obtains last id and number of affected rows with errors separately
func (ExecResult) String ¶ added in v0.4.14
func (r ExecResult) String() (s string)
type StatementCache ¶ added in v0.4.127
type StatementCache struct { // the datasource containing SQL tables DataSource parl.DataSource // contains filtered or unexported fields }
StatementCache caches prepared statements for a data source
func NewStatementCache ¶ added in v0.4.127
func NewStatementCache(dataSource parl.DataSource) (cache *StatementCache)
NewStatementCache returns a cache for prepared statements for a data source
func (*StatementCache) Close ¶ added in v0.4.127
func (c *StatementCache) Close() (err error)
Close shuts down the statement cache