Documentation
¶
Index ¶
- Constants
- func Register(dbtype string, d Driver)
- func WrapContext(ctx context.Context, tx *gorm.DB) context.Context
- type Driver
- type Manager
- type Option
- func WithConnection(maxOpen int, maxIdle int, maxLifetime time.Duration, maxIdleTime time.Duration, ...) Option
- func WithDataSource(source Source) Option
- func WithLogger(logger log.Logger) Option
- func WithMigration(sqlDir string, version uint) Option
- func WithName(name string) Option
- func WithPlugins(plugins ...gorm.Plugin) Option
- func WithType(dbtype string) Option
- type Source
Constants ¶
const ( SQLite = "sqlite" MySQL = "mysql" Postgres = "postgres" Clickhouse = "clickhouse" )
Variables ¶
This section is empty.
Functions ¶
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
}
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 WithLogger ¶
func WithMigration ¶
func WithPlugins ¶ added in v0.6.12
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.
type Source ¶
type Source struct {
Host string
Port uint
User string
Password string `print:"-"`
DBName string
Secure bool
Params map[string]string
}
Source Files
¶
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. |