Documentation ¶
Index ¶
- Variables
- func Bulk(total, batch int, fn func(i, j int) error) (n int, err error)
- func BulkInsert(ctx context.Context, numRows int, q queryable, query Query, ...) (results []interface{}, err error)
- func Listen(ctx context.Context, conn *pgx.Conn, channel string) error
- func Unlisten(ctx context.Context, conn *pgx.Conn, channel string) error
- type Conn
- type Cursors
- type Migration
- type Order
- type Paginator
- type Query
- func (q Query) AscendingOrDescending() Order
- func (q Query) CursorColumn() string
- func (q Query) CursorFromString(cursor string) (interface{}, error)
- func (q Query) NextParamNumber() int
- func (q Query) String() string
- func (q Query) WithPaginator(p *Paginator) (Query, error)
- func (q Query) WithPrefix(prefix string) Query
- func (q Query) WithSuffix(suffix string) Query
- func (q Query) WithTemplateParameter(param string, paramValue interface{}) Query
- func (q Query) WithValues(rows int) Query
- type QueryError
- type QueryOption
- type Store
- type Tx
- type TxInfo
- type TxOption
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // "1" is the number we arbitrarily choose for the schema migrations lock LockMigrations = NewQuery("acquire advisory lock for schema migrations", ` SELECT pg_advisory_xact_lock(1) `) CreateTableSchemaVersion = NewQuery("create table schema_versions", ` CREATE TABLE IF NOT EXISTS schema_versions ( version int, migrated timestamptz NOT NULL DEFAULT NOW(), PRIMARY KEY (version, migrated) ) `) SelectLatestSchemaVersion = NewQuery("select latest schema version", ` SELECT version FROM schema_versions ORDER BY migrated DESC LIMIT 1 `) InsertSchemaVersion = NewQuery("insert schema version", ` INSERT INTO schema_versions(version) VALUES ($1) `) )
Functions ¶
func BulkInsert ¶
Types ¶
type Conn ¶
type Conn interface { Execute(ctx context.Context, query Query, args ...interface{}) (pgconn.CommandTag, error) Get(ctx context.Context, dst interface{}, query Query, args ...interface{}) error Select(ctx context.Context, dst interface{}, query Query, args ...interface{}) error PaginatedSelect(ctx context.Context, dst interface{}, query Query, args ...interface{}) (Cursors, error) }
type Cursors ¶
type Cursors struct { // ...after <cursor> (optional) AfterCursor string // ...or before <cursor> (optional) BeforeCursor string }
Cursors can either be used as part of pagination input to a SELECT query (as part of a Paginator), or new cursors provided as a result of the SELECT.
type Paginator ¶
type Paginator struct { // as in "get the first <n> results..." First int64 // as in "get the last <n> results..." Last int64 Cursors }
Paginator provides pagination parameters for a select query.
func (Paginator) QueryParams ¶
QueryParams returns query parameters which encode the pagination settings and offset.
type Query ¶
type Query struct { Name string // contains filtered or unexported fields }
func NewQuery ¶
func NewQuery(name, query string, opts ...QueryOption) Query
func (Query) AscendingOrDescending ¶
func (Query) CursorColumn ¶
func (Query) CursorFromString ¶
CursorFromString converts a cursor from a string to the format we want to compare in the DB query.
func (Query) NextParamNumber ¶
func (Query) WithPrefix ¶
func (Query) WithSuffix ¶
func (Query) WithTemplateParameter ¶
func (Query) WithValues ¶
type QueryError ¶
func (*QueryError) Error ¶
func (e *QueryError) Error() string
func (*QueryError) Unwrap ¶
func (e *QueryError) Unwrap() error
type QueryOption ¶
type QueryOption func(*Query)
func WithCursorColumn ¶
func WithCursorColumn(column string, paramNumber int, ascendingOrDescending Order) QueryOption
func WithCursorFromString ¶
func WithCursorFromString(cursorFromString func(string) (interface{}, error)) QueryOption
func WithInsertColumns ¶
func WithInsertColumns(cols int) QueryOption
func WithSuffix ¶
func WithSuffix(suffix string) QueryOption
type Store ¶
type TxOption ¶
type TxOption func(*TxInfo)
func WithAccessMode ¶
func WithAccessMode(mode pgx.TxAccessMode) TxOption
func WithDeferrableMode ¶
func WithDeferrableMode(mode pgx.TxDeferrableMode) TxOption
func WithIsoLevel ¶
func WithIsoLevel(level pgx.TxIsoLevel) TxOption
Source Files ¶
Click to show internal directories.
Click to hide internal directories.