dbengine

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound = errors.Errorf("resource not found")
)

Functions

This section is empty.

Types

type BaseModel

type BaseModel struct {
	ID        uint64 `gorm:"primary_key"`
	CreatedAt time.Time
	UpdatedAt time.Time
}

type Conf

type Conf struct {
	MySQLURL          string `env:"MYSQL_URL"`
	MySQLHost         string `env:"MYSQL_HOST"`
	MySQLPort         string `env:"MYSQL_PORT"`
	MySQLUsername     string `env:"MYSQL_USERNAME"`
	MySQLPassword     string `env:"MYSQL_PASSWORD"`
	MySQLDatabase     string `env:"MYSQL_DATABASE"`
	MySQLCharset      string `env:"MYSQL_CHARSET" default:"utf8mb4"`
	MySQLMaxIdleConns int    `env:"MYSQL_MAXIDLECONNS"`
	MySQLMaxOpenConns int    `env:"MYSQL_MAXOPENCONNS"`
	MySQLMaxLifeTime  int64  `env:"MYSQL_MAXLIFETIME"` // 单位秒 (s)
	Debug             bool   `env:"DEBUG"`
}

func LoadDefaultConf

func LoadDefaultConf() (*Conf, error)

type DBEngine

type DBEngine struct {
	*gorm.DB
}

func MustOpen

func MustOpen(c ...*Conf) *DBEngine

MustOpen 强制打开,err 时 panic

func Open

func Open(c ...*Conf) (*DBEngine, error)

Open 构造引擎,打开数据库连接池

func (*DBEngine) Close

func (e *DBEngine) Close() error

Close 关闭数据库连接池

func (*DBEngine) Ping

func (e *DBEngine) Ping() error

Ping ping mysql server

Jump to

Keyboard shortcuts

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