mysqlKit

package
v2.1.31 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateDatabaseIfNotExists added in v2.1.18

func CreateDatabaseIfNotExists(db *gorm.DB, database string) error

CreateDatabaseIfNotExists 自动创建数据库

在 Go 项目中优雅的使用 gorm v2

https://segmentfault.com/a/1190000039097157

func GetDB added in v2.1.17

func GetDB() (*gorm.DB, error)

func MustSetUp added in v2.1.17

func MustSetUp(config *Config, output io.Writer)

func SetUp added in v2.1.17

func SetUp(config *Config, output io.Writer) error

SetUp

@param output 客户端的日志输出(nil: 输出到控制台)

Types

type Config added in v2.1.17

type Config struct {
	DsnConfig

	Log  LogConfig  `json:"log"`
	Pool PoolConfig `json:"pool"`
}

type DsnConfig

type DsnConfig struct {
	UserName string `json:"userName"`
	Password string `json:"password,optional"`
	// Host e.g."127.0.0.1:3306"
	Host   string `json:"host"`
	DBName string `json:"dbName"`
}

func (*DsnConfig) ToDSN added in v2.1.17

func (c *DsnConfig) ToDSN() string

type LogConfig added in v2.1.17

type LogConfig struct {
	SlowThreshold time.Duration   `json:"slowThreshold,default=200ms"`
	LogLevel      logger.LogLevel `json:"logLevel,default=4,options=1|2|3|4"`
}

type PoolConfig

type PoolConfig struct {
	MaxIdleConns    int           `json:"maxIdleConns,default=32"`
	MaxOpenConns    int           `json:"maxOpenConns,default=128"`
	ConnMaxLifetime time.Duration `json:"connMaxLifetime,default=30m"`
}

Jump to

Keyboard shortcuts

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