mysql

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: May 22, 2023 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Connection

func Connection(args ...string) (connection *gorm.DB)

Connection 初始化默认连接 Connection(name) name default is "default" Connection(name, filename)

Types

type Config

type Config struct {
	// 连接地址
	Host string `yaml:"host"`
	// 链接端口号
	Port string `yaml:"port"`
	// 数据库,没有则默认为0
	Database string `yaml:"database"`
	// 数据库链接账号
	UserName string `yaml:"username"`
	// 密码,如果没有则为空
	Password    string `yaml:"password"`
	TablePrefix string `yaml:"prefix"`
	// 最大空闲连接数
	MaxOpenConn int `yaml:"maxopenconn"`
	// 最大连接数
	MaxIdleConn int `yaml:"maxidleconn"`
	// 最大连接时间
	MaxLifeTime            time.Duration `yaml:"maxlifetime"`
	Debug                  bool          `yaml:"debug"`
	SkipDefaultTransaction bool          `yaml:"skip_default_transaction"`
	PrepareStmt            bool          `yaml:"prepare_stmt"`
}

type Conn

type Conn struct {
	// 主库配置
	MasterConfigs []Config `yaml:"Master"`
	// 从库配置
	SlaveConfigs []Config `yaml:"Slave"`
	sync.Once
}

func (*Conn) Init

func (c *Conn) Init() (*gorm.DB, error)

连接数据库

Jump to

Keyboard shortcuts

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