Documentation
¶
Index ¶
- func IsDuplicateKey(err error) bool
- 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 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)
- func (instance *Provider) WithPoolConfig(poolConfig *PoolConfig) *Provider
- func (instance *Provider) WithRetryConfig(retryConfig *RetryConfig) *Provider
- func (instance *Provider) WithTimeoutConfig(timeoutConfig *TimeoutConfig) *Provider
- type ProviderOption
- type RetryConfig
- type TimeoutConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsDuplicateKey ¶
IsDuplicateKey answers on the typed SQLSTATE alone — 23505, unique_violation — read through whichever of the two driver shapes the chain carries. A rendered message is no identity: any error whose text happens to contain those digits (a quoted value, a constraint name) would pass a substring probe, while a driver error wrapped in an exception whose message hides its cause would fail one; errors.As sees through the wrapping either way.
Types ¶
type ConnectionConfig ¶
type ConnectionConfig struct {
// contains filtered or unexported fields
}
func NewConnectionConfig ¶
func (*ConnectionConfig) Database ¶
func (instance *ConnectionConfig) Database() string
func (*ConnectionConfig) Host ¶
func (instance *ConnectionConfig) Host() string
func (*ConnectionConfig) Password ¶
func (instance *ConnectionConfig) Password() string
func (*ConnectionConfig) Port ¶
func (instance *ConnectionConfig) Port() string
func (*ConnectionConfig) SafeContext ¶
func (instance *ConnectionConfig) SafeContext() map[string]any
func (*ConnectionConfig) User ¶
func (instance *ConnectionConfig) User() string
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 v2.1.0
func (instance *Provider) OpenContext(ctx context.Context, params bunorm.ConnectionParameters, logger loggingcontract.Logger) (*bun.DB, error)
OpenContext opens under the caller's context: an already-cancelled context is refused before the attempt, the retry sleeps watch it beside the clock, and the configuration hook and the boot ping derive their budgets from it; pgdialect makes no server round trip at construction, so the first packet is the boot ping's dial under the caller's context. A nil context reads as context.Background(), which is exactly Open. A nil logger reads as the emergency logger, since the terminal branches mark the returned error as logged and the diagnostics routing consumes a process-lifetime once, so both need a sink that writes.
func (*Provider) OpenForMigration ¶ added in v2.1.0
func (instance *Provider) OpenForMigration(params bunorm.ConnectionParameters, logger loggingcontract.Logger) (*bun.DB, error)
OpenForMigration opens the same database with the driver deadlines lifted: ReadTimeout and WriteTimeout are per-operation socket deadlines baked into the connector, sized for request traffic, and a DDL statement that legitimately runs past them — an ALTER TABLE adding constraints on a large table, a long CREATE INDEX — is cut mid-statement with an i/o timeout. The connect timeout stays armed (a down database must still fail fast), the pool is kept to the two connections a sequential migration run needs, and no connection is recycled mid-run — a lifetime rotation under a running statement is the same cut by another name.
func (*Provider) OpenForMigrationContext ¶ added in v2.1.0
func (instance *Provider) OpenForMigrationContext(ctx context.Context, params bunorm.ConnectionParameters, logger loggingcontract.Logger) (*bun.DB, error)
OpenForMigrationContext is OpenForMigration under the caller's context, the way OpenContext is Open under it: the registry hands the context it was constructed with, so an already-cancelled migration is refused before the attempt and a cancellation arriving mid-attempt is honoured at the next cancellable step instead of sleeping out the retry budget. A nil context reads as context.Background(), which is exactly OpenForMigration.
func (*Provider) WithPoolConfig ¶
func (instance *Provider) WithPoolConfig(poolConfig *PoolConfig) *Provider
func (*Provider) WithRetryConfig ¶
func (instance *Provider) WithRetryConfig(retryConfig *RetryConfig) *Provider
func (*Provider) WithTimeoutConfig ¶
func (instance *Provider) WithTimeoutConfig(timeoutConfig *TimeoutConfig) *Provider
type ProviderOption ¶
type ProviderOption func(provider *Provider)
func WithInsecure ¶ added in v2.0.1
func WithInsecure(insecure bool) ProviderOption
func WithPostBuildHook ¶
func WithPostBuildHook(hook PostBuildHook) ProviderOption
func WithTlsConfig ¶ added in v2.0.1
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 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