Documentation
¶
Index ¶
- Constants
- Variables
- func LogVersion(ctx context.Context, kind config.DBKind, db *sql.DB, logger logx.Logger) error
- func Open(cfg config.DataSourceConfig, options ...Option) (*sql.DB, error)
- func SupportsKind(kind config.DBKind) bool
- func Version(ctx context.Context, kind config.DBKind, db *sql.DB) (string, error)
- type ConnectionPoolConfig
- type DatabaseError
- type Option
- type Provider
Constants ¶
const ( DefaultMaxIdleConnsMultiplier = 4 DefaultMaxOpenConnsMultiplier = 16 DefaultMinIdleConns = 25 DefaultMinOpenConns = 100 DefaultConnMaxIdleTime = 5 * time.Minute DefaultConnMaxLifetime = 30 * time.Minute )
Variables ¶
var (
ErrUnsupportedDBKind = errors.New("unsupported database type")
)
Functions ¶
func LogVersion ¶ added in v0.27.0
LogVersion resolves the provider for kind, logs the connected server version, and emits a ready line. It no-ops when kind has no registered provider. The orm data source start hook calls it so version introspection stays inside the database layer.
func Open ¶ added in v0.27.0
Open establishes a connection to the configured data source and returns the raw *sql.DB with the connection pool applied. Building an ORM handle on top of it (bun.DB, dialect, query hooks) is the caller's concern — see internal/orm.
func SupportsKind ¶ added in v0.27.0
SupportsKind reports whether a connection provider is registered for kind. It lets higher layers (e.g. orm.DialectFor) assert that the connector and dialect halves of a dialect agree on the same set of supported kinds.
Types ¶
type ConnectionPoolConfig ¶
type ConnectionPoolConfig struct {
MaxIdleConns int
MaxOpenConns int
ConnMaxIdleTime time.Duration
ConnMaxLifetime time.Duration
}
func NewDefaultConnectionPoolConfig ¶
func NewDefaultConnectionPoolConfig() *ConnectionPoolConfig
type DatabaseError ¶
func (*DatabaseError) Error ¶
func (e *DatabaseError) Error() string
func (*DatabaseError) Unwrap ¶
func (e *DatabaseError) Unwrap() error
type Option ¶
type Option func(*databaseOptions)
func WithConnectionPool ¶
func WithConnectionPool(poolConfig *ConnectionPoolConfig) Option
WithConnectionPool overrides the default connection pool configuration applied to the opened *sql.DB.
type Provider ¶ added in v0.27.0
type Provider interface {
// Connect establishes a database connection and returns the *sql.DB and any error.
Connect(config *config.DataSourceConfig) (*sql.DB, error)
// Kind returns the database kind this provider handles (postgres, mysql, or sqlite).
Kind() config.DBKind
// ValidateConfig checks that the data source configuration is valid before attempting to connect.
ValidateConfig(config *config.DataSourceConfig) error
// Version queries and returns the database server version string.
Version(ctx context.Context, db *sql.DB) (string, error)
}
Provider defines the contract for database-specific connection and validation logic.