db

package
v0.6.12 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SQLite     = "sqlite"
	MySQL      = "mysql"
	Postgres   = "postgres"
	Clickhouse = "clickhouse"
)

Variables

This section is empty.

Functions

func Register added in v0.4.7

func Register(dbtype string, d Driver)

Register makes a Driver available under the given dbtype name. It is meant to be called from the init() of a driver subpackage; double-registration panics so misconfiguration surfaces at startup.

func WrapContext

func WrapContext(ctx context.Context, tx *gorm.DB) context.Context

Types

type Driver added in v0.4.7

type Driver struct {
	Dialector func(dsn string) gorm.Dialector
	Migration func(sqlDB *sql.DB) (database.Driver, error)
	DSN       func(s Source) (string, error)
	Cleanup   func(db *gorm.DB, dbName string, schema bool) error
}

Driver bundles the per-database-engine hooks needed by the manager. Each driver subpackage under pkg/services/db/drivers/* registers a Driver during its init() so the core package never imports concrete GORM or golang-migrate drivers.

type Manager

type Manager interface {
	// business
	model.Database
	// health.go: Alive guards the manager's own wiring (Init reconnects, so
	// a restart is the remedy); Ready pings the database - an unreachable
	// server is not-ready, never a liveness failure.
	common.Liveness
	common.Readiness
	// lifecycle
	common.Initializable
	common.Debuggable
}

func New

func New(opts ...Option) Manager

type Option

type Option func(*manager)

func WithConnection

func WithConnection(maxOpen int, maxIdle int, maxLifetime time.Duration, maxIdleTime time.Duration, execTimeout time.Duration) Option

WithConnection sets the pool knobs. A zero reads as unset - setDefaults fills it - so a wiring layer can pass an absent config key straight through.

func WithDataSource

func WithDataSource(source Source) Option

func WithLogger

func WithLogger(logger log.Logger) Option

func WithMigration

func WithMigration(sqlDir string, version uint) Option

func WithName

func WithName(name string) Option

func WithPlugins added in v0.6.12

func WithPlugins(plugins ...gorm.Plugin) Option

WithPlugins adds GORM plugins to install on the connection. They are installed in order every time the manager connects, so a restart re-applies them to the rebuilt *gorm.DB. Repeated calls append rather than replace.

The core package stays free of concrete plugin imports the same way it stays free of concrete drivers: framingo's own plugins live in pkg/services/db/plugins/*, and an app pulls in only the ones it wires.

func WithType

func WithType(dbtype string) Option

type Source

type Source struct {
	Host     string
	Port     uint
	User     string
	Password string `print:"-"`
	DBName   string
	Secure   bool
	Params   map[string]string
}

func (*Source) DSN

func (s *Source) DSN(dbtype string) (string, error)

DSN resolves the driver registered for dbtype and asks it to format the DSN. The driver subpackage must be blank-imported for this to succeed.

func (*Source) GetParams added in v0.4.7

func (s *Source) GetParams() map[string]string

GetParams returns a defensive copy of s.Params so drivers can mutate it while building a DSN without affecting the caller's Source.

Directories

Path Synopsis
drivers
clickhouse
Package clickhouse registers the ClickHouse GORM dialector, golang-migrate driver, DSN builder, and cleanup hooks with pkg/services/db.
Package clickhouse registers the ClickHouse GORM dialector, golang-migrate driver, DSN builder, and cleanup hooks with pkg/services/db.
mysql
Package mysql registers the MySQL GORM dialector, golang-migrate driver, DSN builder, and cleanup hooks with pkg/services/db.
Package mysql registers the MySQL GORM dialector, golang-migrate driver, DSN builder, and cleanup hooks with pkg/services/db.
postgres
Package postgres registers the Postgres GORM dialector, golang-migrate driver, DSN builder, and cleanup hooks with pkg/services/db.
Package postgres registers the Postgres GORM dialector, golang-migrate driver, DSN builder, and cleanup hooks with pkg/services/db.
sqlite
Package sqlite registers the SQLite GORM dialector, golang-migrate driver, DSN builder, and cleanup hooks with pkg/services/db.
Package sqlite registers the SQLite GORM dialector, golang-migrate driver, DSN builder, and cleanup hooks with pkg/services/db.
plugins
otelgorm
Package otelgorm installs OpenTelemetry tracing on the db service's GORM connection, emitting one client span per statement.
Package otelgorm installs OpenTelemetry tracing on the db service's GORM connection, emitting one client span per statement.

Jump to

Keyboard shortcuts

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