psql2

package
v0.4.180 Latest Latest
Warning

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

Go to latest
Published: May 27, 2024 License: ISC Imports: 7 Imported by: 1

Documentation

Overview

Package psql2 contains types supporting psql functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExecValues

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 NewExecResult

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

func QueryString

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

func ScanToInt

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

func ScanToString

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

Types

type ExecResult

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

func (r *ExecResult) Get() (ID int64, rows int64)

Get obtains last id and number of affected rows with errors separately

func (ExecResult) String

func (r ExecResult) String() (s string)

type StatementCache

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

func NewStatementCache(dataSource parl.DataSource) (cache *StatementCache)

NewStatementCache returns a cache for prepared statements for a data source

func (*StatementCache) Close

func (c *StatementCache) Close() (err error)

Close shuts down the statement cache

func (*StatementCache) Stmt

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

Stmt returns a cached prepared statement from the cache or prepares, caches and returns a new prepared statement

func (*StatementCache) WrapStmt

func (c *StatementCache) WrapStmt(stmt *sql.Stmt) (stm Stmt)

WrapStmt retruns a wrapped statement if the data source support it

  • wrapper is used for retries of databases like SQLite3 that may always return busy errors

type Stmt

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

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