postgres

package
v0.0.0-...-d5dcd45 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package postgres implements postgres connection.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnableToConnect = errors.New("all attempts are exceeded. Unable to connect to instance")

ErrUnableToConnect is returned when unable to connect to the postgres.

Functions

This section is empty.

Types

type ConnectionConfig

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

ConnectionConfig is a configuration for postgres connection.

func NewConnectionConfig

func NewConnectionConfig(host, port, dbname, username, password, sslmode string) ConnectionConfig

NewConnectionConfig creates a new ConnectionConfig.

type Option

type Option func(*Postgres)

Option is a functional option for configuring a Postgres.

func WithConnAttempts

func WithConnAttempts(connAttempts int) Option

WithConnAttempts sets the max attempts for connecting to the Postgres.

func WithConnTimeout

func WithConnTimeout(connTimeout time.Duration) Option

WithConnTimeout sets the timeout for connecting to the Postgres.

func WithMaxPoolSize

func WithMaxPoolSize(maxPoolSize int) Option

WithMaxPoolSize sets the max pool size for the Postgres.

type PgxPool

type PgxPool interface {
	Close()
	Exec(ctx context.Context, sql string, arguments ...interface{}) (pgconn.CommandTag, error)
	Query(ctx context.Context, sql string, optionsAndArgs ...interface{}) (pgx.Rows, error)
	QueryRow(ctx context.Context, sql string, optionsAndArgs ...interface{}) pgx.Row
}

PgxPool is a PostgreSQL connection pool.

type Postgres

type Postgres struct {
	Builder sq.StatementBuilderType
	Pool    PgxPool
	// contains filtered or unexported fields
}

Postgres is a postgres connection.

func New

func New(ctx context.Context, connectionConfig ConnectionConfig, opts ...Option) (*Postgres, error)

New creates a new postgres connection.

func (*Postgres) Close

func (p *Postgres) Close()

Close closes the postgres connection.

Jump to

Keyboard shortcuts

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