database

package
v0.28.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 5, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultMaxIdleConnsMultiplier = 4
	DefaultMaxOpenConnsMultiplier = 16
	DefaultMinIdleConns           = 25
	DefaultMinOpenConns           = 100
	DefaultConnMaxIdleTime        = 5 * time.Minute
	DefaultConnMaxLifetime        = 30 * time.Minute
)

Variables

This section is empty.

Functions

func LogVersion added in v0.27.0

func LogVersion(ctx context.Context, kind config.DBKind, db *sql.DB, logger logx.Logger) error

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

func Open(cfg config.DataSourceConfig) (*sql.DB, error)

Open establishes a connection to the configured data source and returns the raw *sql.DB with the default 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

func SupportsKind(kind config.DBKind) bool

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.

func Version added in v0.27.0

func Version(ctx context.Context, kind config.DBKind, db *sql.DB) (string, error)

Version resolves the provider for kind and returns the connected server's version string. It returns an unsupported-kind error when no provider is registered for kind.

Types

type ConnectionPoolConfig

type ConnectionPoolConfig struct {
	MaxIdleConns    int
	MaxOpenConns    int
	ConnMaxIdleTime time.Duration
	ConnMaxLifetime time.Duration
}

func NewDefaultConnectionPoolConfig

func NewDefaultConnectionPoolConfig() *ConnectionPoolConfig

func (*ConnectionPoolConfig) ApplyToDB

func (c *ConnectionPoolConfig) ApplyToDB(db interface {
	SetMaxIdleConns(int)
	SetMaxOpenConns(int)
	SetConnMaxIdleTime(time.Duration)
	SetConnMaxLifetime(time.Duration)
},
)

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
	// 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 logic.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL