gormKit

package
v2.9.106 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 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, logConfig *LogConfig)

func NewLogger

func NewLogger(logConfig *LogConfig) logger.Interface

NewLogger

参考: logger.Default

func SetUp

func SetUp(config *Config, logConfig *LogConfig) (err error)

SetUp

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

func StringToLevel

func StringToLevel(str string) (level logger.LogLevel, err error)

StringToLevel

4种日志级别:

logger.Silent	屏蔽所有输出
logger.Error	允许: error
logger.Warn		允许: warn、error
logger.Info		允许: info、warn、error

Types

type Config

type Config struct {
	DsnConfig

	Pool PoolConfig `json:"pool" yaml:"pool"`
}

type DsnConfig

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

func (*DsnConfig) GetDsnString

func (c *DsnConfig) GetDsnString() string

type LogConfig

type LogConfig struct {
	Output io.Writer

	SlowThreshold             time.Duration
	LogLevel                  logger.LogLevel
	Colorful                  bool
	IgnoreRecordNotFoundError bool
}

type PoolConfig

type PoolConfig struct {
	MaxIdleConns    int           `json:"maxIdleConns" yaml:"maxIdleConns"`
	MaxOpenConns    int           `json:"maxOpenConns" yaml:"maxOpenConns"`
	ConnMaxLifetime time.Duration `json:"connMaxLifetime" yaml:"connMaxLifetime"`
}

Jump to

Keyboard shortcuts

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