postgres

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2021 License: Apache-2.0 Imports: 13 Imported by: 1

Documentation

Index

Constants

View Source
const DefaultPGPoolMaxConn = 10

DefaultPGPoolMaxConn is an arbitrary number of connections that I decided was ok for the pool

Variables

This section is empty.

Functions

This section is empty.

Types

type Connector

type Connector struct {
	ConnectionString string
}

Connector implements connection.Handler

func (*Connector) Open

Open opens a connection to postgres and returns it wrapped into a connection.DB

type DB

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

DB wraps pgx.Conn into a struct that implements connection.DB

func (*DB) BeginTransaction

func (d *DB) BeginTransaction(ctx context.Context) (connection.DB, error)

BeginTransaction returns a new DB that will use the transaction instead of the basic conn. if the transaction is already started the same will be returned.

func (*DB) BulkInsert

func (d *DB) BulkInsert(ctx context.Context, tableName string, columns []string, values [][]interface{}) (execError error)

BulkInsert will use postgres copy function to try to insert a lot of data. You might need to use pgx types for the values to reduce probability of failure. https://godoc.org/github.com/jackc/pgx#Conn.CopyFrom

func (*DB) Clone

func (d *DB) Clone() connection.DB

Clone returns a copy of DB with the same underlying Connection

func (*DB) CommitTransaction

func (d *DB) CommitTransaction(ctx context.Context) error

CommitTransaction commits the transaction if any is in course, behavior comes straight from pgx.

func (*DB) EExec added in v0.1.16

func (d *DB) EExec(ctx context.Context, statement string, args ...interface{}) error

EExec calls EscapeArgs before invoking Exec

func (*DB) EQuery added in v0.1.16

func (d *DB) EQuery(ctx context.Context, statement string, fields []string, args ...interface{}) (connection.ResultFetch, error)

EQuery calls EscapeArgs before invoking Query

func (*DB) EQueryIter added in v0.1.16

func (d *DB) EQueryIter(ctx context.Context, statement string, fields []string, args ...interface{}) (connection.ResultFetchIter, error)

EQueryIter Calls EscapeArgs before invoking QueryIter

func (*DB) EQueryPrimitive added in v0.1.16

func (d *DB) EQueryPrimitive(ctx context.Context, statement string, field string, args ...interface{}) (connection.ResultFetch, error)

EQueryPrimitive calls EscapeArgs before invoking QueryPrimitive.

func (*DB) ERaw added in v0.1.16

func (d *DB) ERaw(ctx context.Context, statement string, args []interface{}, fields ...interface{}) error

ERaw calls EscapeArgs before invoking Raw

func (*DB) Exec

func (d *DB) Exec(ctx context.Context, statement string, args ...interface{}) error

Exec will run the statement and expect nothing in return.

func (*DB) ExecResult added in v0.1.17

func (d *DB) ExecResult(ctx context.Context, statement string, args ...interface{}) (int64, error)

ExecResult will run the statement and return the number of rows affected.

func (*DB) IsTransaction

func (d *DB) IsTransaction() bool

IsTransaction indicates if the DB is in the middle of a transaction.

func (*DB) Query

func (d *DB) Query(ctx context.Context, statement string, fields []string, args ...interface{}) (connection.ResultFetch, error)

Query returns a function that allows recovering the results of the query, beware the connection is held until the returned closure is invoked.

func (*DB) QueryIter

func (d *DB) QueryIter(ctx context.Context, statement string, fields []string, args ...interface{}) (connection.ResultFetchIter, error)

QueryIter returns an iterator that can be used to fetch results one by one, beware this holds the connection until fetching is done. the passed fields are supposed to correspond to the fields being brought from the db, no check is performed on this.

func (*DB) QueryPrimitive added in v0.1.9

func (d *DB) QueryPrimitive(ctx context.Context, statement string, _ string, args ...interface{}) (connection.ResultFetch, error)

QueryPrimitive returns a function that allows recovering the results of the query but to a slice of a primitive type, only allowed if the query fetches one field.

func (*DB) Raw

func (d *DB) Raw(ctx context.Context, statement string, args []interface{}, fields ...interface{}) error

Raw will run the passed statement with the passed args and scan the first result, if any, to the passed fields.

func (*DB) RollbackTransaction

func (d *DB) RollbackTransaction(ctx context.Context) error

RollbackTransaction rolls back the transaction if any is in course, behavior comes straight from pgx.

func (*DB) Set

func (d *DB) Set(ctx context.Context, set string) error

Set tries to run `SET LOCAL` with the passed parameters if there is an ongoing transaction. https://www.postgresql.org/docs/9.2/static/sql-set.html

Jump to

Keyboard shortcuts

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