package dbx import ( "time" "github.com/jackc/pgx/v5" ) // Option is a functional option for NewCluster. type Option func(*Config) // WithLogger sets the logger for the cluster. func WithLogger(l Logger) Option { return func(c *Config) { c.Logger = l } } // WithMetrics sets the metrics hook for the cluster. func WithMetrics(m *MetricsHook) Option { return func(c *Config) { c.Metrics = m } } // WithRetry overrides the retry configuration. func WithRetry(r RetryConfig) Option { return func(c *Config) { c.Retry = r } } // WithHealthCheck overrides the health check configuration. func WithHealthCheck(h HealthCheckConfig) Option { return func(c *Config) { c.HealthCheck = h } } // WithSlowQueryThreshold sets the threshold for slow query warnings. // Queries taking longer than d will be logged at Warn level. func WithSlowQueryThreshold(d time.Duration) Option { return func(c *Config) { c.SlowQueryThreshold = d } } // WithTracer sets the pgx.QueryTracer on master and all replica configs. // This enables OpenTelemetry integration via libraries like otelpgx. func WithTracer(t pgx.QueryTracer) Option { return func(c *Config) { c.Master.Tracer = t for i := range c.Replicas { c.Replicas[i].Tracer = t } } } // ApplyOptions applies functional options to a Config. func ApplyOptions(cfg *Config, opts ...Option) { for _, o := range opts { o(cfg) } }