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 ¶
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; the dial and the handshake are bounded by the connect timeout under the caller's context, and the dialect query bun runs at construction goes over the connection the ping established, so a mid-attempt cancellation is honoured at the next cancellable step. 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-connection settings 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 — is cut mid-statement with "invalid connection", outside any transaction MySQL would roll back. 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.1.0
func WithInsecure(insecure bool) ProviderOption
WithInsecure disables TLS when set, leaving a plaintext connection, unless WithTlsConfig hands an explicit configuration, which wins. It is the deliberate opt-out from the secure default the provider dials with — a verifying TLS session — for a database reached over a trusted network or one that speaks no TLS, spelled the same as its pgsql sibling.
func WithPostBuildHook ¶
func WithPostBuildHook(hook PostBuildHook) ProviderOption
func WithTlsConfig ¶ added in v2.1.0
func WithTlsConfig(tlsConfig *tls.Config) ProviderOption
WithTlsConfig hands the connector an explicit TLS configuration, taking precedence over both the secure default and WithInsecure. A caller uses it to pin a server certificate, present a client certificate, or otherwise shape the session beyond the system-roots verification the default performs.
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
}
func DefaultTimeoutConfig ¶
func DefaultTimeoutConfig() *TimeoutConfig