Documentation
¶
Index ¶
- Constants
- func IsDuplicateKey(err error) bool
- func RegisterLockerService(registrar ServiceRegistrar, database *bun.DB)
- type ConnectionConfig
- func (instance *ConnectionConfig) Database() string
- func (instance *ConnectionConfig) Host() string
- func (instance *ConnectionConfig) Password() string
- func (instance *ConnectionConfig) Port() string
- func (instance *ConnectionConfig) SafeContext() map[string]any
- func (instance *ConnectionConfig) User() string
- type Locker
- type LockerOption
- type Module
- type ModuleConfig
- type PoolConfig
- type PostBuildHook
- type Provider
- func (instance *Provider) Open(params bunorm.ConnectionParameters, logger loggingcontract.Logger) (*bun.DB, error)
- func (instance *Provider) OpenContext(ctx context.Context, params bunorm.ConnectionParameters, ...) (*bun.DB, error)
- func (instance *Provider) OpenForMigration(params bunorm.ConnectionParameters, logger loggingcontract.Logger) (*bun.DB, error)
- func (instance *Provider) OpenForMigrationContext(ctx context.Context, params bunorm.ConnectionParameters, ...) (*bun.DB, error)
- type ProviderOption
- func WithInsecure(insecure bool) ProviderOption
- func WithPoolConfig(poolConfig *PoolConfig) ProviderOption
- func WithPostBuildHook(hook PostBuildHook) ProviderOption
- func WithRetryConfig(retryConfig *RetryConfig) ProviderOption
- func WithTimeoutConfig(timeoutConfig *TimeoutConfig) ProviderOption
- func WithTlsConfig(tlsConfig *tls.Config) ProviderOption
- type RetryConfig
- type ServiceRegistrar
- type TimeoutConfig
Constants ¶
const Unlimited = -1
Unlimited lifts the bound of a PoolConfig or TimeoutConfig field: no deadline for a timeout, no cap on the open or idle connections, no recycling for a lifetime or an idle time. Every negative value reads the same, so a duration read from configuration as -1s lifts it too; a zero field is unset and takes the constructor default, so a configuration assembled from environment keys nobody set keeps the bounds.
Variables ¶
This section is empty.
Functions ¶
func IsDuplicateKey ¶
IsDuplicateKey answers on the typed SQLSTATE 23505 alone: a rendered message is no identity.
func RegisterLockerService ¶ added in v3.3.0
func RegisterLockerService(registrar ServiceRegistrar, database *bun.DB)
RegisterLockerService publishes the PostgreSQL advisory-lock Locker under the framework's own locker service name, the one lock.LockerMustFromContainer reads, so the backend is a matter of configuration. A process wiring two backends registers the second under a name of its own.
Types ¶
type ConnectionConfig ¶ added in v3.3.0
type ConnectionConfig struct {
// contains filtered or unexported fields
}
func NewConnectionConfig ¶ added in v3.3.0
func (*ConnectionConfig) Database ¶ added in v3.3.0
func (instance *ConnectionConfig) Database() string
func (*ConnectionConfig) Host ¶ added in v3.3.0
func (instance *ConnectionConfig) Host() string
func (*ConnectionConfig) Password ¶ added in v3.3.0
func (instance *ConnectionConfig) Password() string
func (*ConnectionConfig) Port ¶ added in v3.3.0
func (instance *ConnectionConfig) Port() string
func (*ConnectionConfig) SafeContext ¶ added in v3.3.0
func (instance *ConnectionConfig) SafeContext() map[string]any
func (*ConnectionConfig) User ¶ added in v3.3.0
func (instance *ConnectionConfig) User() string
type Locker ¶ added in v3.2.0
type Locker struct {
// contains filtered or unexported fields
}
Locker holds the database handle and the release timeout, both fixed at construction. An advisory lock lives in postgres, on the connection that took it, so one Locker serves concurrent callers without a lock of its own.
func NewLocker ¶ added in v3.2.0
func NewLocker(database *bun.DB, options ...LockerOption) *Locker
NewLocker returns a lockcontract.Locker backed by PostgreSQL session advisory locks (pg_try_advisory_lock / pg_advisory_unlock). A session advisory lock has no expiry: it is held by the backend session that took it until it is explicitly released or that session ends. Each lock therefore pins a dedicated *sql.Conn for its lifetime so the lock stays bound to one backend session, and every release runs on a fresh context so a canceled request context can never strand a held lock on a connection that is returning to the pool.
func (*Locker) CreateLock ¶ added in v3.2.0
type LockerOption ¶ added in v3.2.0
type LockerOption func(*Locker)
func WithLockReleaseTimeout ¶ added in v3.2.0
func WithLockReleaseTimeout(releaseTimeout time.Duration) LockerOption
type Module ¶ added in v3.3.0
type Module struct {
// contains filtered or unexported fields
}
func NewModule ¶ added in v3.3.0
func NewModule(config ModuleConfig) *Module
func (*Module) Description ¶ added in v3.3.0
func (*Module) RegisterServices ¶ added in v3.3.0
func (instance *Module) RegisterServices(registrar applicationcontract.ServiceRegistrar)
RegisterServices publishes nothing unless the application asked for the locker AND handed a database to take it on. Either half missing publishes nothing, silently, rather than a default: a module registered without a database would publish a provider whose NewLocker panics when the locker is first resolved, and one that registered the locker unasked would silently take the framework's locker name away from whatever backend the application meant to use.
type ModuleConfig ¶ added in v3.3.0
type PoolConfig ¶
type PoolConfig struct {
MaxOpenConnections int
MaxIdleConnections int
ConnectionMaxLifetime time.Duration
ConnectionMaxIdleTime time.Duration
}
func DefaultPoolConfig ¶
func DefaultPoolConfig() *PoolConfig
func NewPoolConfig ¶
type PostBuildHook ¶
type Provider ¶
type Provider struct {
// contains filtered or unexported fields
}
func NewProvider ¶
func NewProvider( providerOptions ...ProviderOption, ) *Provider
func (*Provider) Open ¶
func (instance *Provider) Open(params bunorm.ConnectionParameters, logger loggingcontract.Logger) (*bun.DB, error)
func (*Provider) OpenContext ¶ added in v3.3.0
func (instance *Provider) OpenContext(ctx context.Context, params bunorm.ConnectionParameters, logger loggingcontract.Logger) (*bun.DB, error)
OpenContext reads a nil context as context.Background() and a nil logger as the emergency logger for its own records.
func (*Provider) OpenForMigration ¶ added in v3.3.0
func (instance *Provider) OpenForMigration(params bunorm.ConnectionParameters, logger loggingcontract.Logger) (*bun.DB, error)
OpenForMigration lifts the driver deadlines: a DDL statement past them is cut mid-statement with an i/o timeout.
func (*Provider) OpenForMigrationContext ¶ added in v3.3.0
func (instance *Provider) OpenForMigrationContext(ctx context.Context, params bunorm.ConnectionParameters, logger loggingcontract.Logger) (*bun.DB, error)
type ProviderOption ¶
type ProviderOption func(provider *Provider)
func WithInsecure ¶ added in v3.1.0
func WithInsecure(insecure bool) ProviderOption
func WithPoolConfig ¶
func WithPoolConfig(poolConfig *PoolConfig) ProviderOption
func WithPostBuildHook ¶
func WithPostBuildHook(hook PostBuildHook) ProviderOption
func WithRetryConfig ¶
func WithRetryConfig(retryConfig *RetryConfig) ProviderOption
func WithTimeoutConfig ¶
func WithTimeoutConfig(timeoutConfig *TimeoutConfig) ProviderOption
func WithTlsConfig ¶ added in v3.1.0
func WithTlsConfig(tlsConfig *tls.Config) ProviderOption
type RetryConfig ¶
type RetryConfig struct {
MaxAttempts uint32
InitialDelay time.Duration
MaxDelay time.Duration
BackoffMultiplier float64
}
func DefaultRetryConfig ¶
func DefaultRetryConfig() *RetryConfig
func NewRetryConfig ¶
type ServiceRegistrar ¶ added in v3.3.0
type ServiceRegistrar interface {
RegisterService(serviceName string, provider any, options ...containercontract.RegisterOption)
}
type TimeoutConfig ¶
type TimeoutConfig struct {
ConnectTimeout time.Duration
ReadTimeout time.Duration
WriteTimeout time.Duration
}
TimeoutConfig names every deadline the driver applies, so none governs invisibly: left out, pgdriver's own defaults of 10 seconds per read and 5 per write would cut every query that runs past them.
func DefaultTimeoutConfig ¶
func DefaultTimeoutConfig() *TimeoutConfig
func NewTimeoutConfig ¶
func NewTimeoutConfig( connectTimeout time.Duration, ) *TimeoutConfig
NewTimeoutConfig sets the connect timeout and leaves the read and write deadlines zero, which the provider reads as their defaults; NewTimeoutConfigWithDeadlines sets all three.
func NewTimeoutConfigWithDeadlines ¶ added in v3.3.0
func NewTimeoutConfigWithDeadlines( connectTimeout time.Duration, readTimeout time.Duration, writeTimeout time.Duration, ) *TimeoutConfig
NewTimeoutConfigWithDeadlines sets the connect timeout and the driver's read and write deadlines; a zero field takes its default and a negative one reads as Unlimited.