Documentation ¶
Overview ¶
Package pgxh implements some helper functions for "github.com/jackc/pgx".
Index ¶
- func MustPrepare(p PgxPreparer, sql string) (stmtName string)
- func MustPrepareAll(p PgxPreparer, sqls ...string) (stmtNames []string)
- func MustPrepareAllInPlace(p PgxPreparer, stmts ...*string)
- func MustPrepareInPlace(p PgxPreparer, stmt *string)
- func ScanAll(conn PgxQueryer, sql string, dst sqlh.MultiScannable, args ...interface{}) error
- type PgxPreparer
- type PgxQueryer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MustPrepare ¶
func MustPrepare(p PgxPreparer, sql string) (stmtName string)
MustPrepare is like pgxConn[Pool].Prepare but panics if the SQL cannot be parsed. It simplifies safe initialization of global variables holding prepared statements. It also assign name to prepared statement (currently name is "stmt<number>").
func MustPrepareAll ¶
func MustPrepareAll(p PgxPreparer, sqls ...string) (stmtNames []string)
MustPrepareAll is like MustPrepare but accept multiple sql to prepare. It return slice of statements names.
func MustPrepareAllInPlace ¶
func MustPrepareAllInPlace(p PgxPreparer, stmts ...*string)
MustPrepareAllInPlace is modification of MustPrepareAll with resulting statements names stored in original strings with sql.
func MustPrepareInPlace ¶
func MustPrepareInPlace(p PgxPreparer, stmt *string)
MustPrepareInPlace is modification of MustPrepare with resulting statement name stored in original string with sql.
func ScanAll ¶
func ScanAll(conn PgxQueryer, sql string, dst sqlh.MultiScannable, args ...interface{}) error
ScanAll is adaptation of "github.com/apaxa-go/helper/databaseh/sqlh" StmtScanAll for "github.com/jackc/pgx". ScanAll performs query sql on connection conn with arguments 'args' and stores all result rows in dst. sql passed as-is to conn.Query so it is possible to pass prepared statement name as sql. ScanAll stop working on first error. Example:
type Label struct { Id int32 Name string } func (l *Label) SQLScanInterface() []interface{} { return []interface{}{ &l.Id, &l.Name, } } type Labels []*Label func (l *Labels) SQLNewElement() sqlh.SingleScannable { e := &Label{} *l = append(*l, e) return e } ... var labels Labels if err := pgxh.ScanAll(conn, "SELECT id, name FROM LABELS where amount>$1", &labels, someAmount); err != nil { return err }
Types ¶
type PgxPreparer ¶
type PgxPreparer interface {
Prepare(name, sql string) (*pgx.PreparedStatement, error)
}
PgxPreparer interface can hold any object that can prepare SQL statements. Currently (and is primary used for) it can hold pgx.Conn & pgx.ConnPool.