Documentation ¶
Index ¶
- Variables
- func ConnectPgxPool(ctx context.Context, c Config) (err error)
- func ConnectStdLib(ctx context.Context, c Config) error
- func Exec(ctx context.Context, sql string, args ...interface{}) (pgconn.CommandTag, error)
- func MigrateEntryPoint(config Config, optionally1EmbeddedDirs ...embed.FS)
- func MigrateGetDbDriver(ctx context.Context, c Config) (pgDatabaseDriver database.Driver, err error)
- func MigrateGetInstance(ctx context.Context, c Config, embeddedDirs ...embed.FS) (migrateInstance *migrate.Migrate, err error)
- func MigrateGetSource(ctx context.Context, c Config, embeddedDirs ...embed.FS) (migrationSourceDriver source.Driver, err error)
- func MigrateGetSourceFs(ctx context.Context, c Config, embeddedDirs ...embed.FS) (migrationFS fs.FS, err error)
- func QbExec(ctx context.Context, builtQuery sq.Sqlizer) (c pgconn.CommandTag, err error)
- func QbQuery(ctx context.Context, builtQuery sq.Sqlizer) (pgx.Rows, error)
- func QbQueryRow(ctx context.Context, builtQuery sq.Sqlizer) (pgx.Row, error)
- func Query(ctx context.Context, sql string, args ...interface{}) (pgx.Rows, error)
- func QueryRow(ctx context.Context, sql string, args ...interface{}) pgx.Row
- type Config
- type EnhancedDbPool
- func (p *EnhancedDbPool) AcquireCtx(c context.Context) (atx *ctxConn, err error)
- func (p *EnhancedDbPool) BeginCtx(c context.Context) (atx *ctxTx, err error)
- func (p *EnhancedDbPool) BeginTxCtx(c context.Context, t pgx.TxOptions) (atx *ctxTx, err error)
- func (p *EnhancedDbPool) Exec(ctx context.Context, sql string, args ...interface{}) (pgconn.CommandTag, error)
- func (p *EnhancedDbPool) QbExec(ctx context.Context, builtQuery sq.Sqlizer) (c pgconn.CommandTag, err error)
- func (p *EnhancedDbPool) QbQuery(ctx context.Context, builtQuery sq.Sqlizer) (pgx.Rows, error)
- func (p *EnhancedDbPool) QbQueryRow(ctx context.Context, builtQuery sq.Sqlizer) (pgx.Row, error)
- func (p *EnhancedDbPool) Query(ctx context.Context, sql string, args ...interface{}) (pgx.Rows, error)
- func (p *EnhancedDbPool) QueryRow(ctx context.Context, sql string, args ...interface{}) pgx.Row
- type PoolParam
- type QueryExecer
Constants ¶
This section is empty.
Variables ¶
var Qb adaptedStatementBuilder = adaptedStatementBuilder{sq.StatementBuilder.PlaceholderFormat(sq.Dollar)}
Qb is exported squirrel query builder initiated with dollar format for convenience
var QueryExecerCtxKey queryExecerCtxKeyType
var StdDb *sql.DB
StdDb is pgx's stadard library SQL adaptor, initiated by ConnectStdLib. Do not use before the initialization.
Functions ¶
func ConnectPgxPool ¶
ConnectPgxPool initiate the exported DbPool with database connection using pgx pool connection
func ConnectStdLib ¶
ConnectStdLib initiate the exported StdDb with database connection using pgx stdlib
func MigrateEntryPoint ¶
MigrateEntryPoint is the entrypoint for DB migration commands. If config.MigrationFromEmbedded is true, the (optional) embedded migration directory must then be set (only 1 is accepted)
The simplest way to include the embed:
import "embed" //go:embed migrations var embeddedMigrations embed.FS
func MigrateGetDbDriver ¶ added in v0.0.4
func MigrateGetDbDriver(ctx context.Context, c Config) (pgDatabaseDriver database.Driver, err error)
MigrateGetDbDriver exposes the lower-level migration integration
func MigrateGetInstance ¶ added in v0.0.4
func MigrateGetInstance(ctx context.Context, c Config, embeddedDirs ...embed.FS) (migrateInstance *migrate.Migrate, err error)
MigrateGetInstance exposes the lower-level migration integration
func MigrateGetSource ¶ added in v0.0.4
func MigrateGetSource(ctx context.Context, c Config, embeddedDirs ...embed.FS) (migrationSourceDriver source.Driver, err error)
MigrateGetSource exposes the lower-level migration integration
func MigrateGetSourceFs ¶ added in v0.0.5
func MigrateGetSourceFs(ctx context.Context, c Config, embeddedDirs ...embed.FS) (migrationFS fs.FS, err error)
MigrateGetSourceFs exposes the lower-level migration integration
func QbExec ¶ added in v0.0.6
QbExec takes a finished Squirrel's query builder and executes the resulting statement using the default DbPool
func QbQuery ¶ added in v0.0.6
QbQuery takes a finished Squirrel's query builder and executes the resulting query using the default DbPool
func QbQueryRow ¶ added in v0.0.6
QbQueryRow takes a finished Squirrel's query builder and executes the resulting query using the default DbPool
Types ¶
type Config ¶
type Config struct { // If set, URL will override other connection parameters // // Use this parameter to specify more advanced connection parameters such as SSL URL string `yaml:"URL" env:"PG_URL"` Host string `yaml:"Host" env:"PG_HOST"` Port int `yaml:"Port" env:"PG_PORT"` Database string `yaml:"Database" env:"PG_DATABASE"` Username string `yaml:"Username" env:"PG_USERNAME"` Password string `yaml:"Password" env:"PG_PASSWORD"` SSL string `yaml:"SSL" env:"PG_SSL"` PoolParam PoolParam `yaml:"PoolParam"` MigrationStatementTimeoutSeconds int `yaml:"MigrationStatementTimeoutSeconds" env:"PG_MIGRATION_STATEMENT_TIMEOUT_SECONDS"` MigrationFromEmbedded bool `yaml:"MigrationFromEmbedded" env:"PG_MIGRATION_FROM_EMBEDDED"` MigrationDirectory string `yaml:"MigrationDirectory" env:"PG_MIGRATION_DIRECTORY"` }
type EnhancedDbPool ¶ added in v0.1.0
var DbPool *EnhancedDbPool
DbPool is PGX pool connection, initiated by ConnectPgxPool. Do not use before the initialization.
func (*EnhancedDbPool) AcquireCtx ¶ added in v0.1.0
func (p *EnhancedDbPool) AcquireCtx(c context.Context) (atx *ctxConn, err error)
Acquire returns *pgx.Conn wrapped together with context.Context. As such, there is no need to pass Conn to DB calls that might optionally be called with a Conn.
func (*EnhancedDbPool) BeginCtx ¶ added in v0.1.0
func (p *EnhancedDbPool) BeginCtx(c context.Context) (atx *ctxTx, err error)
BeginCtx returns pgx.Tx wrapped together with context.Context. As such, there is no need to pass Tx to DB calls that might optionally be called with Tx.
func (*EnhancedDbPool) BeginTxCtx ¶ added in v0.1.0
func (p *EnhancedDbPool) BeginTxCtx(c context.Context, t pgx.TxOptions) (atx *ctxTx, err error)
BeginCtx returns pgx.Tx wrapped together with context.Context. As such, there is no need to pass Tx to DB calls that might optionally be called with Tx.
func (*EnhancedDbPool) Exec ¶ added in v0.1.0
func (p *EnhancedDbPool) Exec(ctx context.Context, sql string, args ...interface{}) (pgconn.CommandTag, error)
Exec tries to find QueryExecer from ctx, and if not found, executes the query using its pool
func (*EnhancedDbPool) QbExec ¶ added in v0.1.0
func (p *EnhancedDbPool) QbExec(ctx context.Context, builtQuery sq.Sqlizer) (c pgconn.CommandTag, err error)
QbExec takes a finished Squirrel's query builder and executes the resulting statement
func (*EnhancedDbPool) QbQuery ¶ added in v0.1.0
QbQuery takes a finished Squirrel's query builder and executes the resulting query
func (*EnhancedDbPool) QbQueryRow ¶ added in v0.1.0
QbQueryRow takes a finished Squirrel's query builder and executes the resulting query
type PoolParam ¶ added in v0.1.0
type PoolParam struct { // Non-zero values will be passed to DbPool initialization. Defaults to 0. MinConns int `yaml:"MinConns" env:"pg_min_conns"` // Non-zero values will be passed to DbPool initialization. Defaults to max(numCPU, 4) MaxConns int `yaml:"MaxConns" env:"pg_max_conns"` // Non-zero values will be passed to DbPool initialization. Set with time units (s, m, h). Defaults to 2 mins. ConnectTimeout string `yaml:"ConnectTimeout" env:"pg_connect_timeout"` // Non-zero values will be passed to DbPool initialization. Set with time units (s, m, h). Defaults to 30 mins. MaxConnIdleTime string `yaml:"MaxConnIdleTime" env:"pg_max_conn_idle_time"` // Non-zero values will be passed to DbPool initialization. Set with time units (s, m, h). Defaults to 1 hour. MaxConnLifetime string `yaml:"MaxConnLifetime" env:"pg_max_conn_lifetime"` // Non-zero values will be passed to DbPool initialization. Set with time units (s, m, h). Defaults to 60s. HealthCheckPeriod string `yaml:"HealthCheckPeriod" env:"pg_health_check_period"` }