Documentation
¶
Index ¶
- Constants
- func NewGormZapLogger(l *zap.Logger, logLevel string, slowThreshold time.Duration) logger.Interface
- func NewMysqlDB(lc fx.Lifecycle, opts *MySQLConfigOptions, logger *zap.Logger) (*gorm.DB, error)
- func NewPostgresDB(lc fx.Lifecycle, opts *PostgresConfigOptions, logger *zap.Logger) (*gorm.DB, error)
- func NewSQLServer(lc fx.Lifecycle, opts *SQLServerConfigOptions, logger *zap.Logger) (*gorm.DB, error)
- func NewSQLite(lc fx.Lifecycle, opts *SQLiteConfigOptions, logger *zap.Logger) (*gorm.DB, error)
- type DatabaseConfig
- type GormZapLogger
- func (g *GormZapLogger) Error(ctx context.Context, msg string, data ...interface{})
- func (g *GormZapLogger) Info(ctx context.Context, msg string, data ...interface{})
- func (g *GormZapLogger) LogMode(level logger.LogLevel) logger.Interface
- func (g *GormZapLogger) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error)
- func (g *GormZapLogger) Warn(ctx context.Context, msg string, data ...interface{})
- type MySQLConfigOptions
- type PostgresConfigOptions
- type SQLServerConfigOptions
- type SQLiteConfigOptions
Constants ¶
View Source
const ( MySQLDefaultDns = "root:123456@tcp(localhost:3306)/test?charset=utf8mb4&parseTime=True&loc=Local&allowPublicKeyRetrieval=true" PostgresDefaultDns = "host=localhost user=postgres password=123456 dbname=postgres port=5432 sslmode=disable TimeZone=Asia/Shanghai" SQLServerDefaultDsn = "sqlserver://sa:your_password@localhost:1433?database=master" SQLiteDefaultDsn = "test.db" MaxOpenConns = 10 MaxIdleConns = 5 ConnMaxLifetime = 10 * time.Minute )
Variables ¶
This section is empty.
Functions ¶
func NewGormZapLogger ¶
NewGormZapLogger 构造器
func NewMysqlDB ¶
NewMySQLDB
func NewPostgresDB ¶
func NewPostgresDB(lc fx.Lifecycle, opts *PostgresConfigOptions, logger *zap.Logger) (*gorm.DB, error)
NewPostgresDB
func NewSQLServer ¶
func NewSQLServer(lc fx.Lifecycle, opts *SQLServerConfigOptions, logger *zap.Logger) (*gorm.DB, error)
NewSQLServer
Types ¶
type DatabaseConfig ¶
type DatabaseConfig struct {
LogLevel string `mapstructure:"log_level"`
SlowThreshold time.Duration `mapstructure:"slow_threshold"`
DryRun bool `mapstructure:"dry_run"`
MaxOpenConns int `mapstructure:"max_open_conns"`
MaxIdleConns int `mapstructure:"max_idle_conns"`
ConnMaxLifetime time.Duration `mapstructure:"conn_max_lifetime"`
*gorm.Config
}
type GormZapLogger ¶
type GormZapLogger struct {
// contains filtered or unexported fields
}
GormZapLogger 让GORM日志走zap
func (*GormZapLogger) Error ¶
func (g *GormZapLogger) Error(ctx context.Context, msg string, data ...interface{})
func (*GormZapLogger) Info ¶
func (g *GormZapLogger) Info(ctx context.Context, msg string, data ...interface{})
func (*GormZapLogger) LogMode ¶
func (g *GormZapLogger) LogMode(level logger.LogLevel) logger.Interface
实现 logger.Interface 四个方法
type MySQLConfigOptions ¶
type MySQLConfigOptions struct {
DatabaseConfig
MySQLCfg mysql.Config
}
MySQLConfigOptions 公共字段 + 扩展字段
type PostgresConfigOptions ¶
type PostgresConfigOptions struct {
DatabaseConfig `mapstructure:",squash"`
PgSQLCfg postgres.Config
}
PostgresConfigOptions
type SQLServerConfigOptions ¶
type SQLServerConfigOptions struct {
DatabaseConfig
SQLServerCfg sqlserver.Config
}
type SQLiteConfigOptions ¶
type SQLiteConfigOptions struct {
DatabaseConfig
SQLiteCfg sqlite.Config
}
Click to show internal directories.
Click to hide internal directories.