db

package
v0.4.10 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

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

Variables

This section is empty.

Functions

func AppendParams added in v0.4.7

func AppendParams(dsn string, params map[string]string, firstSep, sep string) string

AppendParams formats params as key=value pairs joined by sep and prefixed by firstSep, producing a deterministic ordering. Exported so driver subpackages can share the formatting logic.

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

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

Jump to

Keyboard shortcuts

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