db

package
v0.9.10 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 23 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 panics on double registration.

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 is registered from a drivers/* subpackage's init() so the core imports no engine.

type Manager

type Manager interface {
	model.Database
	// destructive ops, hidden from model.Database holders
	model.DatabaseDebugger
	// an unreachable server fails Ready, never Alive
	common.Liveness
	common.Readiness
	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 defaults of db.connection.max_open, max_idle, max_lifetime, max_idle_time and exec_timeout (built-in: 10, 5, 5m, never, 30s; zero is unset).

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

WithName also sets the config root: <name>.connection.* instead of db.connection.*.

func WithPlugins added in v0.6.12

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

WithPlugins appends; plugins are reinstalled in order on every connect.

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) CloneParams added in v0.8.1

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

CloneParams returns a mutable copy, never nil.

func (*Source) DSN

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

DSN fails unless the dbtype's driver package is blank-imported.

Directories

Path Synopsis
drivers
clickhouse
Package clickhouse registers the ClickHouse driver with pkg/services/db; blank-import it.
Package clickhouse registers the ClickHouse driver with pkg/services/db; blank-import it.
mysql
Package mysql registers the MySQL driver with pkg/services/db; blank-import it.
Package mysql registers the MySQL driver with pkg/services/db; blank-import it.
postgres
Package postgres registers the Postgres driver with pkg/services/db; blank-import it.
Package postgres registers the Postgres driver with pkg/services/db; blank-import it.
sqlite
Package sqlite registers the SQLite driver (mattn/go-sqlite3) with pkg/services/db; blank-import it.
Package sqlite registers the SQLite driver (mattn/go-sqlite3) with pkg/services/db; blank-import it.
plugins
otelgorm
Package otelgorm traces GORM statements; a separate package because upstream imports the clickhouse, mysql and postgres dialectors.
Package otelgorm traces GORM statements; a separate package because upstream imports the clickhouse, mysql and postgres dialectors.

Jump to

Keyboard shortcuts

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