pqx

package
v0.0.0-...-d988ceb Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Driver is a driver name.
	Driver = "postgres"
)

Variables

This section is empty.

Functions

func CheckConnection

func CheckConnection(ctx context.Context, maxTries int, db *sql.DB) error

CheckConnection returns an error if connection is not ready. Otherwise, return nil. CheckConnection calls db.Ping to check if the connection is open, but that doesn't guarantee the database is ready to execute a query. So in addition to using db.Ping, CheckConnection also performs one-round-trip queries to the database.

Use context.WithTimeout make a deadline.

func Open

func Open(cfg *Config) (*sql.DB, error)

Open knows how to open a new database connection. The Open just validate its arguments without creating a connection to the database. To verify that the data source name is valid, call database.CheckConnection.

The returned DB is safe for concurrent use by multiple goroutines and maintains its own pool of idle connections. Thus, the Open function should be called just once. It is rarely necessary to close a DB.

Types

type Config

type Config struct {
	Name              string
	Host              string
	User              string
	Pass              string
	Timezone          string
	SSLEnabled        bool
	MaxOpenConnection int
	MaxIdleConnection int
}

Config is the required setting to open database connection.

func (*Config) DSN

func (c *Config) DSN() string

DSN returns config as DSN URI from.

Jump to

Keyboard shortcuts

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