Documentation
¶
Index ¶
- Constants
- func RemoveConfig(name ...string)
- func SetConfig(name string, cfg *Config)
- func SetConfigByMap(m map[string]any, name ...string) error
- type Config
- func (c *Config) AddPlugin(plugins ...gorm.Plugin)
- func (c *Config) AddReplica(replica Config)
- func (c *Config) SetConfigWithMap(config map[string]any) error
- func (c *Config) SetLogger(logger *mlog.Logger)
- func (c *Config) SetPlugins(plugins []gorm.Plugin)
- func (c *Config) SetReplicas(replicas []Config)
- type DB
- type GormLogger
- func (l *GormLogger) Error(ctx context.Context, msg string, args ...interface{})
- func (l *GormLogger) Info(ctx context.Context, msg string, args ...interface{})
- func (l *GormLogger) LogMode(level logger.LogLevel) logger.Interface
- func (l *GormLogger) Trace(ctx context.Context, begin time.Time, ...)
- func (l *GormLogger) Warn(ctx context.Context, msg string, args ...interface{})
- type Option
Constants ¶
const (
// DefaultName is the default group name for db instance.
DefaultName = "default"
)
Variables ¶
This section is empty.
Functions ¶
func RemoveConfig ¶
func RemoveConfig(name ...string)
RemoveConfig removes the db configuration with the specified name.
Types ¶
type Config ¶
type Config struct {
Type string
DSN string
Host string
Port string
User string
Password string
DBName string
MaxIdleTime time.Duration
MaxIdleConnection int
MaxOpenConnection int
MaxLifetime time.Duration
Logger *mlog.Logger
SlowThreshold time.Duration // slow query threshold
Replicas []Config // replicas list
Plugins []gorm.Plugin // plugins list
}
func ConfigFromMap ¶
ConfigFromMap parses and returns config from given map.
func DefaultConfig ¶
func DefaultConfig() *Config
func GetConfig ¶
GetConfig returns the db configuration with the specified name. If `name` is not passed, it returns configuration of the default name.
func (*Config) AddReplica ¶
func (*Config) SetPlugins ¶
func (*Config) SetReplicas ¶
type DB ¶
type GormLogger ¶
type GormLogger struct {
// contains filtered or unexported fields
}
GormLogger is a custom GORM logger that integrates with mlog.
func NewGormLogger ¶
func NewGormLogger(mlogger *mlog.Logger, opts ...Option) *GormLogger
NewGormLogger creates a new GormLogger.
func (*GormLogger) Error ¶
func (l *GormLogger) Error(ctx context.Context, msg string, args ...interface{})
Error logs an error message.
func (*GormLogger) Info ¶
func (l *GormLogger) Info(ctx context.Context, msg string, args ...interface{})
Info logs an info message.
func (*GormLogger) LogMode ¶
func (l *GormLogger) LogMode(level logger.LogLevel) logger.Interface
LogMode returns a new logger with a different log level.
type Option ¶
type Option func(*GormLogger)
Option is a functional option for configuring the GormLogger.
func WithLogLevel ¶
WithLogLevel sets the GORM log level.
func WithSkipErrRecordNotFound ¶
WithSkipErrRecordNotFound sets whether to skip ErrRecordNotFound errors.
func WithSlowThreshold ¶
WithSlowThreshold sets the slow query threshold.