psql

package
v0.4.63 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2023 License: ISC Imports: 6 Imported by: 1

Documentation

Overview

Package psql augments database/sql

Index

Constants

This section is empty.

Variables

View Source
var DBFactory = &dbFactory{}

Functions

func DelFromContext

func DelFromContext(ctx context.Context, key string) (ok bool)

DelFromContext removes a value from context. Thread-safe

func DiscardDB

func DiscardDB(ctx context.Context)

DiscardDB removes db handle from context

func ExecValues added in v0.4.14

func ExecValues(execResult sql.Result, e error) (ID, rows int64, err error)

ExecValues parses the result from an Exec* method into its values. if LastInsertId or RowsAffected fails, the error is added to err.

func GetDB

func GetDB(ctx context.Context) (db *sql.DB)

GetDB obtains db handle from context

func NewExecResult added in v0.4.14

func NewExecResult(execResult sql.Result, e error) (result parl.ExecResult, err error)

func QueryString added in v0.4.26

func QueryString(label string, ctx context.Context, dataSource parl.DataSource,
	query string, args ...any) (value string, err error)

func ScanToInt added in v0.4.14

func ScanToInt(sqlRow *sql.Row, e error) (value int, err error)

func ScanToString added in v0.4.26

func ScanToString(sqlRow *sql.Row, e error) (value string, err error)

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.

func StoreDB

func StoreDB(ctx context.Context, db *sql.DB)

StoreDB saves db handle in context

func StoreInContext

func StoreInContext(ctx context.Context, key string, value interface{}) (ok bool)

StoreInContext stores a value in context. Thread-safe

Types

type Context

type Context struct {
	context.Context
	Map sync.Map
}

Context is a context.Context with a Value() implementation

func NewContext

func NewContext(ctx ...context.Context) (c *Context)

NewContext provides a context.Context with a Value() implementation

func (*Context) Delete

func (c *Context) Delete(key string)

StoreInContext stores a value in context. Thread-safe

func (*Context) Store

func (c *Context) Store(key string, value interface{})

StoreInContext stores a value in context. Thread-safe

func (*Context) Value

func (c *Context) Value(key interface{}) (result interface{})

Value retrieves data from context. Thread-safe

func (*Context) Value2

func (c *Context) Value2(key interface{}) (result interface{}, ok bool)

Value2 retrieves data and was–present indicator from context. Thread-safe

type DBCache added in v0.4.14

type DBCache struct {
	// contains filtered or unexported fields
}

func NewDBCache added in v0.4.14

func NewDBCache(dataSource parl.DataSource) (dc *DBCache)

func (*DBCache) Close added in v0.4.14

func (dc *DBCache) Close() (err error)

func (*DBCache) Stmt added in v0.4.14

func (dc *DBCache) Stmt(query string, ctx context.Context) (stmt *sql.Stmt, err error)

func (*DBCache) WrapStmt added in v0.4.26

func (dc *DBCache) WrapStmt(stmt *sql.Stmt) (stm Stmt)

type DBMap added in v0.4.14

type DBMap struct {
	// contains filtered or unexported fields
}

func NewDBMap added in v0.4.14

func NewDBMap(dsnr parl.DataSourceNamer,
	schema func(dataSource parl.DataSource, ctx context.Context) (err error)) (dbMap *DBMap)

func (*DBMap) Close added in v0.4.14

func (dm *DBMap) Close() (err error)

func (*DBMap) Exec added in v0.4.14

func (dm *DBMap) Exec(
	partition parl.DBPartition, query string, ctx context.Context,
	args ...any) (execResult parl.ExecResult, err error)

func (*DBMap) Query added in v0.4.14

func (dm *DBMap) Query(
	partition parl.DBPartition, query string, ctx context.Context,
	args ...any) (sqlRows *sql.Rows, err error)

func (*DBMap) QueryInt added in v0.4.14

func (dm *DBMap) QueryInt(
	partition parl.DBPartition, query string, ctx context.Context,
	args ...any) (value int, err error)

func (*DBMap) QueryRow added in v0.4.14

func (dm *DBMap) QueryRow(
	partition parl.DBPartition, query string, ctx context.Context,
	args ...any) (sqlRow *sql.Row, err error)

func (*DBMap) QueryString added in v0.4.14

func (dm *DBMap) QueryString(
	partition parl.DBPartition, query string, ctx context.Context,
	args ...any) (value string, err error)

type ExecResult added in v0.4.14

type ExecResult struct {
	ID int64
	// 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 Stmt added in v0.4.26

type Stmt interface {
	ExecContext(ctx context.Context, args ...any) (sqlResult sql.Result, err error)
	QueryContext(ctx context.Context, args ...any) (sqlRows *sql.Rows, err error)
	QueryRowContext(ctx context.Context, args ...any) (sqlRow *sql.Row)
}

type StmtWrapper added in v0.4.26

type StmtWrapper interface {
	WrapStmt(stmt *sql.Stmt) (stm Stmt)
}

Jump to

Keyboard shortcuts

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