database

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyOptions

func ApplyOptions(opt *option, fns ...Option)

func Init

func Init(dbName string, dbConfig *Config, isDebug bool) error

func RegistryDriver

func RegistryDriver(name string, driver Driver)

Types

type BaseDb

type BaseDb struct {
	*gorm.DB
}

func (*BaseDb) SetEngine

func (b *BaseDb) SetEngine(ctx context.Context, engine string) bool

type ClickhouseDriver

type ClickhouseDriver struct{}

func (ClickhouseDriver) Dial

func (c ClickhouseDriver) Dial(conf *Config) gorm.Dialector

type Config

type Config struct {
	Driver   string `json:"driver" yaml:"driver" validate:"required"`
	Host     string `json:"host" yaml:"host" validate:"required"`
	Database string `json:"database" yaml:"database" validate:"required"`
	Port     int    `json:"port" yaml:"port" validate:"required"`
	Username string `json:"username" yaml:"username" validate:"required"`
	Password string `json:"password" yaml:"password" validate:"required"`

	MaxIdleConnes int `json:"max_idle_connes" yaml:"max_idle_connes" validate:"required"`
	MaxOpenConnes int `json:"max_open_connes" yaml:"max_open_connes" validate:"required"`
	MaxLifetime   int `json:"max_lifetime" yaml:"max_lifetime" validate:"required"`

	WriteTimeout time.Duration `json:"write_timeout" yaml:"write_timeout" validate:"required"`
	ReadTimeout  time.Duration `json:"read_timeout" yaml:"read_timeout" validate:"required"`
}

func (*Config) Validate

func (c *Config) Validate() error

type Driver

type Driver interface {
	Dial(conf *Config) gorm.Dialector
}

func GetDriver

func GetDriver(name string) (_ Driver, exist bool)

type Logger

type Logger struct{}

func (*Logger) Error

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

func (*Logger) Info

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

func (*Logger) LogMode

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

func (*Logger) Trace

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

func (*Logger) Warn

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

type MysqlDriver

type MysqlDriver struct{}

func (MysqlDriver) Dial

func (m MysqlDriver) Dial(conf *Config) gorm.Dialector

type Option

type Option interface {
	Apply(opt *option)
}

func WithDebugLog

func WithDebugLog(isDebug bool) Option

func WithMaxIdleConn

func WithMaxIdleConn(maxIdleConn int) Option

func WithMaxLifetime

func WithMaxLifetime(maxLifetime time.Duration) Option

func WithMaxOpenConn

func WithMaxOpenConn(maxOpenConn int) Option

type PostgreSqlDriver

type PostgreSqlDriver struct{}

func (PostgreSqlDriver) Dial

func (p PostgreSqlDriver) Dial(conf *Config) gorm.Dialector

Jump to

Keyboard shortcuts

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