database

package
v1.1.5 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2022 License: Apache-2.0 Imports: 20 Imported by: 11

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Discard = New(log.New(ioutil.Discard, "", log.LstdFlags), config{})
	Default = New(log.New(os.Stdout, "\r\n", log.LstdFlags), config{
		SlowThreshold: 200 * time.Millisecond,
		LogLevel:      logger.Warn,
		Colorful:      true,
	})
	Recorder = traceRecorder{Interface: Default, BeginAt: time.Now()}
)
View Source
var CONFIG = Mysql{
	Path:         "127.0.0.1:3306",
	Config:       "charset=utf8mb4&parseTime=True&loc=Local",
	Dbname:       "iris-admin",
	Username:     "root",
	Password:     "",
	MaxIdleConns: 0,
	MaxOpenConns: 0,
	LogMode:      false,
	LogZap:       "error",
}
View Source
var ErrDatabaseInit = errors.New("数据库初始化失败")

Functions

func DorpDB

func DorpDB(dsn, driver, dbName string) error

func Init added in v1.1.2

func Init() error

Init 初始化 mysql 配置

func InitMysql

func InitMysql()

InitMysql 初始化数据库

func Instance

func Instance() *gorm.DB

Instance 数据库单例

func IsExist

func IsExist() bool

IsExist 配置文件是否存在

func New

func New(writer writer, config config) logger.Interface

New

func Remove

func Remove() error

Remove 删除配置文件

Types

type Mysql

type Mysql struct {
	Path         string `mapstructure:"path" json:"path" yaml:"path"`
	Config       string `mapstructure:"config" json:"config" yaml:"config"`
	Dbname       string `mapstructure:"db-name" json:"dbname" yaml:"db-name"`
	Username     string `mapstructure:"username" json:"username" yaml:"username"`
	Password     string `mapstructure:"password" json:"password" yaml:"password"`
	MaxIdleConns int    `mapstructure:"max-idle-conns" json:"maxIdleConns" yaml:"max-idle-conns"`
	MaxOpenConns int    `mapstructure:"max-open-conns" json:"maxOpenConns" yaml:"max-open-conns"`
	LogMode      bool   `mapstructure:"log-mode" json:"logMode" yaml:"log-mode"`
	LogZap       string `mapstructure:"log-zap" json:"logZap" yaml:"log-zap"` //silent,error,warn,info,zap
}

func (*Mysql) BaseDsn

func (m *Mysql) BaseDsn() string

Dsn 获取 mysql dsn

func (*Mysql) Dsn

func (m *Mysql) Dsn() string

Dsn 获取 mysql dsn

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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