db

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var StoreInitDB map[string]*StoreDbClient

全局使用DB,就需要把DB定义成公有的

Functions

func NewDB

func NewDB(arr []Mysql) (err error)

NewDB 自动初始化数据库

Types

type Mysql

type Mysql struct {
	Name   string      `mapstructure:"name"`
	Master MysqlConfig `mapstructure:"master"`
	Slave  MysqlConfig `mapstructure:"slave"`
}

type MysqlConfig

type MysqlConfig struct {
	Driver         string  `mapstructure:"driver"`
	DSN            string  `mapstructure:"dsn"`
	MaxOpenConns   int32   `mapstructure:"max_open_conns"`
	MaxIdleConns   int32   `mapstructure:"max_idle_conns"`
	MaxLifeTimeout float64 `mapstructure:"max_life_timeout"`
}

type StoreDbClient

type StoreDbClient struct {
	Name   string
	Config Mysql
	Master *gorm.DB
	Slave  *gorm.DB
}

func LoadDBByName

func LoadDBByName(dbName string) *StoreDbClient

Jump to

Keyboard shortcuts

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