Documentation
¶
Index ¶
- Constants
- func GormConfig(logger *zap.Logger) *gorm.Config
- func InitDB(cfg DatabaseConfig, logger *zap.Logger) (*gorm.DB, error)
- type DatabaseConfig
- type Logger
- func (l Logger) Error(ctx context.Context, str string, args ...interface{})
- func (l Logger) Info(ctx context.Context, str string, args ...interface{})
- func (l Logger) LogMode(level gormlogger.LogLevel) gormlogger.Interface
- func (l Logger) SetAsDefault()
- func (l Logger) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error)
- func (l Logger) Warn(ctx context.Context, str string, args ...interface{})
Constants ¶
View Source
const DatabaseDriverMySQL = "mysql"
View Source
const DatabaseDriverPostgres = "postgres"
View Source
const DatabaseDriverSQLite = "sqlite"
Variables ¶
This section is empty.
Functions ¶
Types ¶
type DatabaseConfig ¶
type DatabaseConfig struct {
Driver string `mapstructure:"driver"`
Path string `mapstructure:"path"`
DSN string `mapstructure:"dsn"`
}
func (DatabaseConfig) GormDialector ¶
func (c DatabaseConfig) GormDialector() (gorm.Dialector, error)
func (DatabaseConfig) ResolvedDriver ¶
func (c DatabaseConfig) ResolvedDriver() (string, error)
func (DatabaseConfig) RuntimeDSN ¶
func (c DatabaseConfig) RuntimeDSN() (string, error)
func (DatabaseConfig) SQLDriverName ¶
func (c DatabaseConfig) SQLDriverName() (string, error)
SQLDriverName returns the driver name to be used with sql.Open for the given database configuration.
type Logger ¶
type Logger struct {
ZapLogger *zap.Logger
LogLevel gormlogger.LogLevel
SlowThreshold time.Duration
SkipCallerLookup bool
IgnoreRecordNotFoundError bool
PrintQuery bool // When true, print the query to the console (without escapes)
}
func (Logger) LogMode ¶
func (l Logger) LogMode(level gormlogger.LogLevel) gormlogger.Interface
func (Logger) SetAsDefault ¶
func (l Logger) SetAsDefault()
Click to show internal directories.
Click to hide internal directories.