Documentation
¶
Index ¶
- Constants
- Variables
- func ConnectDBPool(p params.Database) (*pgxpool.Pool, error)
- func GetLastMigrationAvailable() (uint, error)
- func IsSerializationError(err error) bool
- func IsUniqueViolation(err error) bool
- func MigrateDown(params params.Database) error
- func MigrateTo(p params.Database, version uint, force bool) error
- func MigrateUp(p params.Database) error
- func MigrateVersion(params params.Database) (uint, bool, error)
- func Ping(ctx context.Context, pool *pgxpool.Pool) error
- func Prefix(prefix string) string
- func Select(d Tx, results interface{}, query string, args ...interface{}) error
- func ValidateSchemaUpToDate(params params.Database) error
- type Database
- type DatabaseMigrator
- type Migrator
- type PgxDatabase
- func (d *PgxDatabase) Close()
- func (d *PgxDatabase) Exec(query string, args ...interface{}) (pgconn.CommandTag, error)
- func (d *PgxDatabase) Get(dest interface{}, query string, args ...interface{}) error
- func (d *PgxDatabase) GetPrimitive(dest interface{}, query string, args ...interface{}) error
- func (d *PgxDatabase) Metadata() (map[string]string, error)
- func (d *PgxDatabase) Pool() *pgxpool.Pool
- func (d *PgxDatabase) Query(query string, args ...interface{}) (rows pgx.Rows, err error)
- func (d *PgxDatabase) Select(results interface{}, query string, args ...interface{}) error
- func (d *PgxDatabase) Stats() sql.DBStats
- func (d *PgxDatabase) Transact(fn TxFunc, opts ...TxOpt) (interface{}, error)
- func (d *PgxDatabase) WithContext(ctx context.Context) Database
- type QueryOptions
- type Tx
- type TxFunc
- type TxOpt
- type TxOptions
Constants ¶
View Source
const ( DefaultMaxOpenConnections = 25 DefaultMaxIdleConnections = 25 DefaultConnectionMaxLifetime = 5 * time.Minute DatabaseDriver = "pgx" )
View Source
const ( SerializationRetryMaxAttempts = 10 SerializationRetryStartInterval = time.Millisecond * 2 )
Variables ¶
View Source
var ( ErrNotFound = fmt.Errorf("not found: %w", pgx.ErrNoRows) ErrAlreadyExists = errors.New("already exists") ErrSerialization = errors.New("serialization error") ErrNotASlice = errors.New("results must be a pointer to a slice") )
View Source
var ErrSchemaNotCompatible = errors.New("db schema version not compatible with latest version")
Functions ¶
func ConnectDBPool ¶ added in v0.16.0
ConnectDBPool connects to a database using the database params and returns a connection pool
func IsSerializationError ¶
func IsUniqueViolation ¶
func MigrateDown ¶
func ValidateSchemaUpToDate ¶ added in v0.11.0
Types ¶
type Database ¶
type Database interface {
Tx
Close()
Transact(fn TxFunc, opts ...TxOpt) (interface{}, error)
Metadata() (map[string]string, error)
Stats() sql.DBStats
WithContext(ctx context.Context) Database
Pool() *pgxpool.Pool
}
func BuildDatabaseConnection ¶ added in v0.9.0
BuildDatabaseConnection returns a database connection based on a pool for the configuration in c.
type DatabaseMigrator ¶
type DatabaseMigrator struct {
// contains filtered or unexported fields
}
func NewDatabaseMigrator ¶
func NewDatabaseMigrator(params params.Database) *DatabaseMigrator
type PgxDatabase ¶ added in v0.16.0
type PgxDatabase struct {
// contains filtered or unexported fields
}
func NewPgxDatabase ¶ added in v0.16.0
func NewPgxDatabase(db *pgxpool.Pool) *PgxDatabase
func (*PgxDatabase) Close ¶ added in v0.16.0
func (d *PgxDatabase) Close()
func (*PgxDatabase) Exec ¶ added in v0.16.0
func (d *PgxDatabase) Exec(query string, args ...interface{}) (pgconn.CommandTag, error)
func (*PgxDatabase) Get ¶ added in v0.16.0
func (d *PgxDatabase) Get(dest interface{}, query string, args ...interface{}) error
func (*PgxDatabase) GetPrimitive ¶ added in v0.16.0
func (d *PgxDatabase) GetPrimitive(dest interface{}, query string, args ...interface{}) error
func (*PgxDatabase) Metadata ¶ added in v0.16.0
func (d *PgxDatabase) Metadata() (map[string]string, error)
func (*PgxDatabase) Pool ¶ added in v0.16.0
func (d *PgxDatabase) Pool() *pgxpool.Pool
func (*PgxDatabase) Query ¶ added in v0.16.0
func (d *PgxDatabase) Query(query string, args ...interface{}) (rows pgx.Rows, err error)
func (*PgxDatabase) Select ¶ added in v0.16.0
func (d *PgxDatabase) Select(results interface{}, query string, args ...interface{}) error
func (*PgxDatabase) Stats ¶ added in v0.16.0
func (d *PgxDatabase) Stats() sql.DBStats
func (*PgxDatabase) Transact ¶ added in v0.16.0
func (d *PgxDatabase) Transact(fn TxFunc, opts ...TxOpt) (interface{}, error)
func (*PgxDatabase) WithContext ¶ added in v0.16.0
func (d *PgxDatabase) WithContext(ctx context.Context) Database
type QueryOptions ¶ added in v0.9.0
type QueryOptions struct {
// contains filtered or unexported fields
}
type Tx ¶
type Tx interface {
Query(query string, args ...interface{}) (pgx.Rows, error)
Select(dest interface{}, query string, args ...interface{}) error
Get(dest interface{}, query string, args ...interface{}) error
GetPrimitive(dest interface{}, query string, args ...interface{}) error
Exec(query string, args ...interface{}) (pgconn.CommandTag, error)
}
type TxOpt ¶
type TxOpt func(*TxOptions)
func ReadCommitted ¶ added in v0.16.0
func ReadCommitted() TxOpt
func RepeatableRead ¶ added in v0.16.0
func RepeatableRead() TxOpt
func WithContext ¶
func WithIsolationLevel ¶
func WithIsolationLevel(level pgx.TxIsoLevel) TxOpt
func WithLogger ¶
type TxOptions ¶
type TxOptions struct {
// contains filtered or unexported fields
}
func DefaultTxOptions ¶
func DefaultTxOptions() *TxOptions
Source Files
¶
Click to show internal directories.
Click to hide internal directories.