Documentation
¶
Index ¶
- func ConnectPostgres(c PostgresConfig) (*sql.DB, error)
- func ExecInTx(db *sql.DB, fn ExecInTxFunc) error
- func NewTxInstance(instanceID string) *sql.DB
- func RegisterPostgresTxDb(pgConfig PostgresConfig)
- func ReleaseSavepoint(name string, tx *sql.Tx) error
- func RollbackToSavepoint(name string, tx *sql.Tx) error
- func SetSavepoint(name string, tx *sql.Tx) error
- func SetupPool(c PostgresConfig, db *sql.DB)
- type ExecInTxFunc
- type PostgresConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConnectPostgres ¶
func ConnectPostgres(c PostgresConfig) (*sql.DB, error)
ConnectPostgres connects to postgres
func ExecInTx ¶ added in v0.6.0
func ExecInTx(db *sql.DB, fn ExecInTxFunc) error
ExecInTx executes the provided function within a database transaction. The must return true for the transaction to be commit. Returning false will rollback the transaction. To pass variables into the transaction function or to return variables out, use a closure.
func NewTxInstance ¶
NewTxInstance creates a new instance of tx-db. Make sure you Register first
func RegisterPostgresTxDb ¶
func RegisterPostgresTxDb(pgConfig PostgresConfig)
RegisterPostgresTxDb registers postgres to txdb
func ReleaseSavepoint ¶ added in v0.9.0
ReleaseSavepoint releases a named savepoint previously set in the transaction. This allows the commands executed after the savepoint to be committed.
func RollbackToSavepoint ¶ added in v0.9.0
RollbackToSavepoint rolls back the transaction to the named savepoint.
func SetSavepoint ¶ added in v0.9.0
SetSavepoint sets a named savepoint in the current transaction.
func SetupPool ¶ added in v0.12.0
func SetupPool(c PostgresConfig, db *sql.DB)
Types ¶
type ExecInTxFunc ¶ added in v0.6.0
ExecInTxFunc defines a function type for the ExecInTx function argument.
type PostgresConfig ¶
type PostgresConfig struct {
ApplicationName string `mapstructure:"application_name"`
Host string
Port int
Username string
Password string
Database string
SSLEnabled bool `mapstructure:"ssl_enabled"`
MigrationsTable string `mapstructure:"migrations_table"`
// MaxOpenConnections sets the maximum size of the connection pool. Default 10.
MaxOpenConnections int `mapstructure:"max_open_connections"`
// MaxIdleConnections set the maximum idle connections that are held open. Default 2.
MaxIdleConnections int `mapstructure:"max_idle_connections"`
// MaxConnectionLifetimeMinutes ensures that connections are recycled after a certain amount of time,
// preventing stale connections from accumulating. Default 5 minutes.
MaxConnectionLifetimeMinutes int `mapstructure:"max_connection_lifetime_minutes"`
}
PostgresConfig holds the information for connecting with a postgres database
func (*PostgresConfig) GenerateAddress ¶
func (c *PostgresConfig) GenerateAddress() string
GenerateAddress returns a string with DB connection information
func (PostgresConfig) URL ¶ added in v0.7.0
func (c PostgresConfig) URL() string
URL returns a 'postgres://user:pass@host:port/database?sslmode=' style address