mysqlKit

package
v2.8.181 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NotSetupError = errorKit.New("Haven’t been set up correctly")
)

Functions

func CreateDatabaseIfNotExists

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

CreateDatabaseIfNotExists 自动创建数据库

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

https://segmentfault.com/a/1190000039097157

func GetDB

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

func MustSetUp

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

func SetUp

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

SetUp

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

Types

type Config

type Config struct {
	DsnConfig

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

type DsnConfig

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

func (*DsnConfig) ToDsnString

func (c *DsnConfig) ToDsnString() string

type LogConfig

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

type PoolConfig

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

Jump to

Keyboard shortcuts

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