pgxh

package module
v0.0.0-...-d7f4b64 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2016 License: Apache-2.0 Imports: 3 Imported by: 0

README

PGXH

Build Status Coverage Status Go Report Card GoDoc

Package pgxh implements some helper functions for http://github.com/jackc/pgx .

Documentation

Overview

Package pgxh implements some helper functions for "github.com/jackc/pgx".

Index

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.

type PgxQueryer

type PgxQueryer interface {
	Query(sql string, args ...interface{}) (*pgx.Rows, error)
}

PgxQueryer interface can hold any object that can query SQL statements. Currently (and is primary used for) it can hold pgx.Conn & pgx.ConnPool.

Jump to

Keyboard shortcuts

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