database

package
v0.2.27 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyOptions

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

func Init

func Init(dbName string, conf *Config) error

func NewLogger added in v0.2.0

func NewLogger(fields ...zap.Field) grrmLogger.Interface

func Otlp added in v0.2.0

func Otlp(conf *Config) gorm.Plugin

func RegisterPlugin added in v0.2.0

func RegisterPlugin(name string, fn PluginFunc)

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"`

	Plugins []string `json:"plugins" yaml:"plugins"`
}

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 {
	Fields []zap.Field
}

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 OptionFunc added in v0.2.0

type OptionFunc func(*option)

func WithDebugLog

func WithDebugLog(isDebug bool) OptionFunc

func WithMaxIdleConn

func WithMaxIdleConn(maxIdleConn int) OptionFunc

func WithMaxLifetime

func WithMaxLifetime(maxLifetime time.Duration) OptionFunc

func WithMaxOpenConn

func WithMaxOpenConn(maxOpenConn int) OptionFunc

func WithPlugins added in v0.2.0

func WithPlugins(plugins ...string) OptionFunc

type PluginFunc added in v0.2.0

type PluginFunc func(conf *Config) gorm.Plugin

func PluginFuncByName added in v0.2.0

func PluginFuncByName(name string) (PluginFunc, bool)

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