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(resolver containercontract.Resolver) (*bun.DB, error)
- func (instance *Provider) OpenContext(ctx context.Context, resolver containercontract.Resolver) (*bun.DB, error)
- func (instance *Provider) OpenForMigration(resolver containercontract.Resolver) (*bun.DB, error)
- func (instance *Provider) OpenForMigrationContext(ctx context.Context, resolver containercontract.Resolver) (*bun.DB, error)
- func (instance *Provider) SecretParameterNames() []string
- 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 ¶ added in v1.1.0
type Provider ¶
type Provider struct {
// contains filtered or unexported fields
}
func NewProvider ¶
func NewProviderWithConfig ¶
func NewProviderWithConfig( hostParameterName string, portParameterName string, databaseParameterName string, userParameterName string, passwordParameterName string, poolConfig *PoolConfig, timeoutConfig *TimeoutConfig, retryConfig *RetryConfig, providerOptions ...ProviderOption, ) *Provider
func (*Provider) OpenContext ¶ added in v1.2.0
func (instance *Provider) OpenContext(ctx context.Context, resolver containercontract.Resolver) (*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.
func (*Provider) OpenForMigration ¶ added in v1.2.0
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 v1.2.0
func (instance *Provider) OpenForMigrationContext(ctx context.Context, resolver containercontract.Resolver) (*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) SecretParameterNames ¶ added in v1.2.0
SecretParameterNames names the password parameter, so the registry arms the redaction at construction and a process that never dials, debug:parameters above all, masks it.
func (*Provider) WithPoolConfig ¶
func (instance *Provider) WithPoolConfig(poolConfig *PoolConfig) *Provider
func (*Provider) WithRetryConfig ¶ added in v1.0.1
func (instance *Provider) WithRetryConfig(retryConfig *RetryConfig) *Provider
func (*Provider) WithTimeoutConfig ¶
func (instance *Provider) WithTimeoutConfig(timeoutConfig *TimeoutConfig) *Provider
type ProviderOption ¶ added in v1.1.0
type ProviderOption func(provider *Provider)
func WithInsecure ¶ added in v1.2.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 ¶ added in v1.1.0
func WithPostBuildHook(hook PostBuildHook) ProviderOption
func WithTlsConfig ¶ added in v1.2.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 ¶ added in v1.0.1
type RetryConfig struct {
MaxAttempts uint32
InitialDelay time.Duration
MaxDelay time.Duration
BackoffMultiplier float64
}
func DefaultRetryConfig ¶ added in v1.0.1
func DefaultRetryConfig() *RetryConfig
func NewRetryConfig ¶ added in v1.1.0
type TimeoutConfig ¶
type TimeoutConfig struct {
ConnectTimeout time.Duration
ReadTimeout time.Duration
WriteTimeout time.Duration
}
func DefaultTimeoutConfig ¶
func DefaultTimeoutConfig() *TimeoutConfig