pg

package
v0.0.0-...-9762c8f Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoRows is returned by QueryOne and ExecOne when query returned zero rows
	// but at least one row is expected.
	ErrNoRows = errors.New("pg: at least one row expected, none returned")
	// ErrMultiRows is returned by QueryOne and ExecOne when query returned
	// multiple rows but exactly one row is expected.
	ErrMultiRows = errors.New("pg: many rows returned, one expected")
	// ErrInvalidEnumValue typical error when the enum value is invalid
	ErrInvalidEnumValue = errors.New("pg: invalid value for enum")
	// ErrIntegrityViolation is returned when an integrity constraint is violated
	ErrIntegrityViolation = errors.New("pg: integrity violation")
)

Functions

func ToURL

func ToURL(port int, ssl bool, username, password, db, host string) string

ToURL constructs a Postgres querystring with sensible defaults.

Types

type Config

type Config struct {
	ConnectPGOptions
	SetInternalPGLogger bool
	PGApplicationName   string
	PGLoggerPrefix      string
	MigrationPath       string
	PGPoolSize          int
}

Config is the service configuration

type ConnectPGOptions

type ConnectPGOptions struct {
	ConnectionString string
	RetrySleepTime   time.Duration
	RetryNumTimes    uint16
	// TLSConfig overrides any TLS config parsed from the connection string if not nil
	TLSConfig       *tls.Config
	ConnErrorLogger LogConErrorFunc
}

ConnectPGOptions attempts to connect to a pg instance; retries `RetryNumTimes`

type Database

type Database struct {
	*pg.DB
	// contains filtered or unexported fields
}

Database is a connection to a Postgres database.

func NewDatabase

func NewDatabase(conf Config) (*Database, error)

NewDatabase creates a new database connection.

func (*Database) Close

func (d *Database) Close() error

Close closes the database.

func (*Database) GetMigrationVersion

func (d *Database) GetMigrationVersion(ctx context.Context, v *uint) error

GetMigrationVersion returns what migration we are on.

func (*Database) MigrateDown

func (d *Database) MigrateDown(ctx context.Context) error

MigrateDown performs a down migration.

func (*Database) MigrateUp

func (d *Database) MigrateUp(ctx context.Context, version *uint) error

MigrateUp performs an up migration.

func (*Database) Ping

func (d *Database) Ping(ctx context.Context) (err error)

Ping pings the database to ensure that we can connect to it.

func (*Database) RunInTransaction

func (d *Database) RunInTransaction(ctx context.Context, next func(ctx context.Context) error) error

func (*Database) TruncateAll

func (d *Database) TruncateAll() error

TruncateAll truncates all tables other that schema_migrations.

type LogConErrorFunc

type LogConErrorFunc func(
	numTries int,
	duration time.Duration,
	host string,
	db string,
	user string,
	ssl bool,
	err error,
)

Jump to

Keyboard shortcuts

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