mysql

package
v0.0.0-...-86eff3d Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2020 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrRecordNotFound returns a "record not found error". Occurs only when attempting to query the database with a struct; querying with a slice won't return this error
	ErrRecordNotFound = gorm.ErrRecordNotFound
)

Functions

func GetConnDB

func GetConnDB() *gorm.DB

获取mysql单例对象

func NewInstance

func NewInstance(config Config) (db *gorm.DB, err error)

初始化实例

Types

type Config

type Config struct {
	DBName          string //数据库名称
	User            string //用户名
	Password        string //密码
	Adds            string //连接地址
	Debug           bool   //是否开启 mysql debug
	Charset         string //字符集 (默认 utf8)
	ConnMaxLifetime int    //设置连接可重用的最大时间量
	MaxIdleConns    int    //设置连接池空闲时的最大连接数
	MaxOpenConns    int    //设置数据库的最大打开连接数
	SingularTable   bool   //关闭复数表名,如果设置为true,`User`表的表名就会是`user`,而不是`users`
	gorm.Config
}

type Mysql

type Mysql struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(config Config) (*Mysql, error)

初始化单例客户端

func (*Mysql) Close

func (mysql *Mysql) Close() error

mysql close

func (*Mysql) Ping

func (mysql *Mysql) Ping() error

mysql ping

Jump to

Keyboard shortcuts

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