gormx

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

README

chassix-data-gorm

chassix data access with gorm for mysql、postgres etc.

Documentation

Index

Constants

View Source
const (
	DriverMysql    = "mysql"
	DriverPostgres = "postgres"
)

Variables

This section is empty.

Functions

func CloseAllDB

func CloseAllDB() error

Close close all db connection

func DB

func DB() *gorm.DB

DB get the default(first) *Db connection

func DBs

func DBs() []*gorm.DB

DBs get all database connections

func DefaultLogger

func DefaultLogger(logCfg *LoggerConfig) logger.Interface

func RegisterDriver

func RegisterDriver(dType string, provider DatabaseProvider)

func SetDB

func SetDB(index int, db *gorm.DB)

Types

type DatabaseConfig

type DatabaseConfig struct {
	Dialect     string       `yaml:"dialect"`
	DSN         string       `yaml:"dsn"`
	MaxIdle     int          `yaml:"max_idle"`
	MaxOpen     int          `yaml:"max_open"`
	MaxLifetime int          `yaml:"max_lifetime"`
	ShowSQL     bool         `yaml:"show_sql"`
	Logger      LoggerConfig `yaml:"logger"`
}

DatabaseConfig db datasource

type DatabaseProvider

type DatabaseProvider interface {
	Connect(config *DatabaseConfig) (*gorm.DB, error)
}

type Datasource

type Datasource struct {
	Databases []*DatabaseConfig `yaml:"databases,flow"`
}

func GetDatasource

func GetDatasource() *Datasource

GetDatasource get datasource

type Logger

type Logger struct {
	logger.Config
	// contains filtered or unexported fields
}

func NewLogger

func NewLogger(logCfg *LoggerConfig) *Logger

func (*Logger) Error

func (l *Logger) Error(ctx context.Context, str string, args ...interface{})

func (*Logger) Info

func (l *Logger) Info(ctx context.Context, str string, args ...interface{})

func (*Logger) LogMode

func (l *Logger) LogMode(level logger.LogLevel) logger.Interface

func (*Logger) Trace

func (l *Logger) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error)

func (*Logger) Warn

func (l *Logger) Warn(ctx context.Context, str string, args ...interface{})

type LoggerConfig

type LoggerConfig struct {
	SlowThreshold time.Duration   `yaml:"slow_threshold"`
	Level         logger.LogLevel `yaml:"level"`
	Colorful      bool            `yaml:"colorful"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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