Documentation
¶
Index ¶
- Variables
- func IsErrConnectionFailed(err error) bool
- func NewDB(ctx context.Context, options ...ConfigOption) *bun.DB
- type Config
- type ConfigOption
- func WithApplicationName(applicationName string) ConfigOption
- func WithDatabase(database string) ConfigOption
- func WithDialTimeout(dialTimeout time.Duration) ConfigOption
- func WithHost(host string) ConfigOption
- func WithPassword(password string) ConfigOption
- func WithPort(port int) ConfigOption
- func WithQueryLogging(logRead, logWrite bool) ConfigOption
- func WithReadTimeout(readTimeout time.Duration) ConfigOption
- func WithUser(user string) ConfigOption
- func WithWriteTimeout(writeTimeout time.Duration) ConfigOption
- type HealthCheck
Constants ¶
This section is empty.
Variables ¶
var ErrNotUnique = errors.New("not unique")
Functions ¶
func IsErrConnectionFailed ¶ added in v0.4.5
Types ¶
type Config ¶ added in v0.1.77
type Config struct { Port int `env:"POSTGRES_PORT" envDefault:"5432"` Host string `env:"POSTGRES_HOST" envDefault:"postgres"` Password string `env:"POSTGRES_PASSWORD" envDefault:"mysecretpassword"` User string `env:"POSTGRES_USER" envDefault:"postgres"` Database string `env:"POSTGRES_DB" envDefault:"postgres"` // ApplicationName is the application name. Used in logs on Pg side. // Only availaible from pg-9.0. ApplicationName string `env:"POSTGRES_APPLICATION_NAME" envDefault:"-"` // Dial timeout for establishing new connections. DialTimeout time.Duration `env:"POSTGRES_DIAL_TIMEOUT" envDefault:"5s"` // Name of the Table that is created to try if database is writeable HealthCheckTableName string `env:"POSTGRES_HEALTH_CHECK_TABLE_NAME" envDefault:"healthcheck"` // Amount of time to cache the last health check result HealthCheckResultTTL time.Duration `env:"POSTGRES_HEALTH_CHECK_RESULT_TTL" envDefault:"10s"` // Indicator whether write (insert,update,delete) queries should be logged LogWrite bool `env:"POSTGRES_LOG_WRITES" envDefault:"true"` // Indicator whether read (select) queries should be logged LogRead bool `env:"POSTGRES_LOG_READS" envDefault:"false"` // Timeout for socket reads. If reached, commands will fail // with a timeout instead of blocking. ReadTimeout time.Duration `env:"POSTGRES_READ_TIMEOUT" envDefault:"30s"` // Timeout for socket writes. If reached, commands will fail // with a timeout instead of blocking. WriteTimeout time.Duration `env:"POSTGRES_WRITE_TIMEOUT" envDefault:"30s"` }
type ConfigOption ¶ added in v0.3.4
type ConfigOption func(cfg *Config)
func WithApplicationName ¶ added in v0.3.4
func WithApplicationName(applicationName string) ConfigOption
WithApplicationName -ApplicationName is the application name. Used in logs on Pg side. Only available from pg-9.0.
func WithDatabase ¶ added in v0.3.4
func WithDatabase(database string) ConfigOption
WithDatabase - customise the db name
func WithDialTimeout ¶ added in v0.3.4
func WithDialTimeout(dialTimeout time.Duration) ConfigOption
WithDialTimeout - Dial timeout for establishing new connections.
func WithHost ¶ added in v0.3.4
func WithHost(host string) ConfigOption
WithHost - customise the db host
func WithPassword ¶ added in v0.3.4
func WithPassword(password string) ConfigOption
WithPassword - customise the db password
func WithPort ¶ added in v0.3.4
func WithPort(port int) ConfigOption
WithPort - customize the db port
func WithQueryLogging ¶ added in v0.4.0
func WithQueryLogging(logRead, logWrite bool) ConfigOption
func WithReadTimeout ¶ added in v0.3.4
func WithReadTimeout(readTimeout time.Duration) ConfigOption
WithReadTimeout - Timeout for socket reads. If reached, commands will fail with a timeout instead of blocking.
func WithUser ¶ added in v0.3.4
func WithUser(user string) ConfigOption
WithUser - customise the db user
func WithWriteTimeout ¶ added in v0.3.4
func WithWriteTimeout(writeTimeout time.Duration) ConfigOption
WithWriteTimeout - Timeout for socket writes. If reached, commands will fail with a timeout instead of blocking.
type HealthCheck ¶ added in v0.1.15
type HealthCheck struct {
// contains filtered or unexported fields
}
HealthCheck checks the state of a postgres connection. It must not be changed after it was registered as a health check.
func NewHealthCheck ¶ added in v0.5.0
func NewHealthCheck(db *bun.DB) *HealthCheck
NewHealthCheck creates a new HealthCheck instance.
func (*HealthCheck) CleanUp ¶ added in v0.1.15
func (h *HealthCheck) CleanUp(ctx context.Context) error
CleanUp drops the test table.
func (*HealthCheck) HealthCheck ¶ added in v0.1.15
func (h *HealthCheck) HealthCheck(ctx context.Context) servicehealthcheck.HealthCheckResult
HealthCheck performs the read test on the database. If enabled, it performs a write test as well.