Documentation
¶
Overview ¶
Package pgutil provides utilities for handling Postgres.
Index ¶
Constants ¶
const ( // ErrUnknown is returned for all errors with unknown cause. ErrUnknown = iota // ErrUniqueViolation is returned for unique constraint violations. ErrUniqueViolation // ErrNotNullViolation is returned for non-null constraint violations. ErrNotNullViolation // ErrRecordNotFound is returned when query is expected to return a single record, but none are returned. ErrRecordNotFound // ErrInvalidText is returned when you try assigned invalid value to types such as uuid. ErrInvalidText )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
Client is a wrapper for *gorm.DB providing a handy Close() function.
func DialPostgres ¶
DialPostgres creates a connection to Postgres, and returns Client instance.
type Config ¶ added in v1.1.55
type Config struct {
// DSN is a string that contains basic connection data.
DSN string
// Verbose specifies whether to log all executed queries.
Verbose bool
// PoolMaxOpen is the maximum number of open connections to the database (default: 10).
PoolMaxOpen int
// PoolMaxIdle is the maximum number of connections in the idle connection pool (default: 5).
PoolMaxIdle int
// PoolMaxLifetime is the maximum amount of time a connection may be reused (default: 1h).
PoolMaxLifetime time.Duration
// PoolMaxIdleTime is the maximum amount of time a connection may be idle (default: 30m).
PoolMaxIdleTime time.Duration
// contains filtered or unexported fields
}
Config holds a configuration for Client.
type Error ¶
type Error struct {
// Err is the wrapped error.
Err error
// Code is the error code.
Code int
// Constraint is the name of violated constraint.
Constraint string
// TableName is the name of the table.
TableName string
// ColumnName is the name of the column.
ColumnName string
// Message is the message returned by the DB.
Message string
}
Error represents a wrapped query error.
func TranslateError ¶
TranslateError tries to cast given error instance to PgError and extract enough information to build Error instance.
type Opt ¶ added in v1.1.55
type Opt = func(*Config)
Opt is an option to be specified to DialPostgres.
func PoolMaxIdle ¶ added in v1.1.55
PoolMaxIdle is the maximum number of connections in the idle connection pool.
func PoolMaxIdleTime ¶ added in v1.1.55
PoolMaxIdleTime is the maximum amount of time a connection may be idle.
func PoolMaxLifetime ¶ added in v1.1.55
PoolMaxLifetime is the maximum amount of time a connection may be reused.
func PoolMaxOpen ¶ added in v1.1.55
PoolMaxOpen is the maximum number of open connections to the database.