db

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2025 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const ComponentName = "database"

Variables

This section is empty.

Functions

func DialectorMap added in v0.1.3

func DialectorMap(drivers []DriverOpenFunc, cfgMap map[string]Config) map[string]DialectorConfig

func Logger

func Logger(conf Config) logger.Interface

func NewDB

func NewDB(dialector gorm.Dialector, conf Config) (*gorm.DB, error)

Types

type Config

type Config struct {
	Driver        string `mapstructure:"driver" yaml:"driver"`               // 驱动名称
	Source        string `mapstructure:"source" mask:":([^@]+)@"`            // root:****@tcp(127.0.0.1:3306)/test
	DryRun        bool   `mapstructure:"dryRun" yaml:"dryRun"`               // 是否为测试模式(空跑sql,不会实际操作数据库)
	SlowThreshold int    `mapstructure:"slowThreshold" yaml:"slowThreshold"` // 慢日志阈值
	MaxLifeTime   int    `mapstructure:"maxLifeTime" yaml:"maxLifeTime"`     // 最大连接时间
	MaxOpenConn   int    `mapstructure:"maxOpenConn" yaml:"maxOpenConn"`     // 最大连接数
	MaxIdleConn   int    `mapstructure:"maxIdleConn" yaml:"maxIdleConn"`     // 最大空闲连接数
}

type DBManager

type DBManager map[string]*gorm.DB

多数据源管理

func NewDBManager

func NewDBManager(cfgKV map[string]DialectorConfig) (DBManager, error)

func (DBManager) Default

func (m DBManager) Default() *gorm.DB

func (DBManager) Get

func (m DBManager) Get(k string) *gorm.DB

type DialectorConfig added in v0.1.3

type DialectorConfig struct {
	Dialector gorm.Dialector
	Config    Config
}

type DriverOpenFunc added in v0.1.3

type DriverOpenFunc func(dsn string) gorm.Dialector

Jump to

Keyboard shortcuts

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