postgres

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrCantOpenConnection indicates an error on openning connection to the postgres database.
	ErrCantOpenConnection = errors.New("error on openning connection to the postgres database").WithCode("CANT_OPEN_POSTGRES_CONNECTION")
	// ErrDatabaseNotReached indicates that the database can not be reached.
	ErrDatabaseNotReached = errors.New("the database can not be reached").WithCode("CANT_REACH_POSTGRES_DATABASE")
)

Functions

func Driver added in v0.1.2

func Driver(e env.Environment) string

Driver indicates which Postgres driver should be used based on environment.

Types

type Client

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

Client is a custom postgres client.

func MustNewClient

func MustNewClient(params ClientParams) Client

MustNewClient creates a new Client instance. It uses postgres generic driver by default. If in production environment, uses cloudsqlpostgres driver. It uses 5 max connections by default. It panics if any error is found.

func NewClient

func NewClient(params ClientParams) (Client, error)

NewClient creates a new Client instance. It uses postgres generic driver by default. If in production environment, uses cloudsqlpostgres driver. It uses 5 max connections by default.

func (Client) Connect

func (c Client) Connect(ctx context.Context) (*sql.DB, error)

Connect connects the client with the database.

type ClientParams

type ClientParams struct {
	Tracer         trace.Tracer
	Environment    env.Environment
	MaxConnections int
	DatabaseURI    string
}

ClientParams encapsulates all Client's dependencies.

Jump to

Keyboard shortcuts

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