postgres

package
v0.0.0-...-c283e9f Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2021 License: BSD-3-Clause Imports: 12 Imported by: 32

Documentation

Index

Constants

View Source
const (
	InvalidTextRepresentation = "22P02"
	CheckViolation            = "23514"
	UniqueViolation           = "23505"
	RaiseException            = "P0001"
	ForeignKeyViolation       = "23503"
)

Variables

This section is empty.

Functions

func IsPostgresCode

func IsPostgresCode(err error, code string) bool

func IsUniquenessError

func IsUniquenessError(err error, constraint string) bool

func ResetOnMigration

func ResetOnMigration(db *DB, log log15.Logger, doneCh chan struct{})

Types

type Conf

type Conf struct {
	Discoverd *discoverd.Client
	Service   string
	User      string
	Password  string
	Database  string
}

type DB

type DB struct {
	*pgx.ConnPool
	// contains filtered or unexported fields
}

func New

func New(connPool *pgx.ConnPool, conf *Conf) *DB

func Open

func Open(conf *Conf, afterConn func(*pgx.Conn) error) (*DB, error)

func Wait

func Wait(conf *Conf, afterConn func(*pgx.Conn) error) *DB

func (*DB) Begin

func (db *DB) Begin() (*DBTx, error)

func (*DB) Exec

func (db *DB) Exec(query string, args ...interface{}) error

func (*DB) ExecRetry

func (db *DB) ExecRetry(query string, args ...interface{}) error

func (*DB) Listen

func (db *DB) Listen(channel string, log log15.Logger) (*Listener, error)

Listen creates a listener for the given channel, returning the listener and the first connection error (nil on successful connection).

func (*DB) QueryRow

func (db *DB) QueryRow(query string, args ...interface{}) Scanner

type DBTx

type DBTx struct{ *pgx.Tx }

func (*DBTx) Exec

func (tx *DBTx) Exec(query string, args ...interface{}) error

func (*DBTx) QueryRow

func (tx *DBTx) QueryRow(query string, args ...interface{}) Scanner

type Listener

type Listener struct {
	Notify chan *pgx.Notification
	Err    error
	// contains filtered or unexported fields
}

func (*Listener) Close

func (l *Listener) Close() (err error)

type Migration

type Migration struct {
	ID    int
	Steps []Step
}

type Migrations

type Migrations []Migration

func NewMigrations

func NewMigrations() *Migrations

func (*Migrations) Add

func (m *Migrations) Add(id int, stmts ...string)

func (*Migrations) AddSteps

func (m *Migrations) AddSteps(id int, steps ...Step)

func (Migrations) Migrate

func (m Migrations) Migrate(db *DB) error

type Scanner

type Scanner interface {
	Scan(...interface{}) error
}

type Step

type Step func(*DBTx) error

Jump to

Keyboard shortcuts

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