mysqlKit

package
v2.2.40 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 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" 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 added in v2.2.10

func (c *DsnConfig) ToDsnString() string

type LogConfig added in v2.1.17

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