Documentation ¶
Index ¶
- func FileWithLineNum() string
- type DBLogLevel
- type DBType
- type DatabaseConf
- func (c DatabaseConf) DBOpen(opts ...gorm.Option) (db *gorm.DB)
- func (c DatabaseConf) GetDSN() string
- func (c DatabaseConf) GetLogger() logger.Interface
- func (c DatabaseConf) MysqlDSN() string
- func (c DatabaseConf) NewCacheDriver(redisConf redis2.RedisConf) *gorm.DBdeprecated
- func (c DatabaseConf) NewDriver() (db *gorm.DB)
- func (c DatabaseConf) PostgresDSN() string
- func (c DatabaseConf) SqliteDSN() string
- type DatabaseLogger
- func (l *DatabaseLogger) Error(ctx context.Context, msg string, data ...interface{})
- func (l *DatabaseLogger) Info(ctx context.Context, msg string, data ...interface{})
- func (l *DatabaseLogger) LogMode(level logger.LogLevel) logger.Interface
- func (l *DatabaseLogger) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error)
- func (l *DatabaseLogger) Warn(ctx context.Context, msg string, data ...interface{})
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type DBLogLevel ¶
type DBLogLevel string
const ( Info DBLogLevel = "info" Warn DBLogLevel = "warn" Error DBLogLevel = "error" Silent DBLogLevel = "silent" )
func (DBLogLevel) ToGormLogLevel ¶
func (l DBLogLevel) ToGormLogLevel() (logLevel logger.LogLevel)
type DatabaseConf ¶
type DatabaseConf struct { Host string `json:",env=DATABASE_HOST"` Port int `json:",env=DATABASE_PORT"` Username string `json:",default=root,env=DATABASE_USERNAME"` Password string `json:",optional,env=DATABASE_PASSWORD"` DBName string `json:",default=sa,env=DATABASE_DBNAME"` SSLMode string `json:",optional,env=DATABASE_SSL_MODE"` Type DBType `json:",default=mysql,options=[mysql,postgres,sqlite3],env=DATABASE_TYPE"` MaxOpenConn int `json:",optional,default=100,env=DATABASE_MAX_OPEN_CONN"` CacheTime int `json:",optional,default=10,env=DATABASE_CACHE_TIME"` DBPath string `json:",optional,env=DATABASE_DBPATH"` MysqlConfig string `json:",optional,env=DATABASE_MYSQL_CONFIG"` PGConfig string `json:",optional,env=DATABASE_PG_CONFIG"` SqliteConfig string `json:",optional,env=DATABASE_SQLITE_CONFIG"` LogLevel DBLogLevel `json:",default=info,options=[info,warn,error,silent],env=DATABASE_LOG_LEVEL"` // 日志级别,枚举(info、warn、error和silent) SlowThreshold int `json:",optional,default=1000"` // 记录慢查询阈值,单位毫秒 }
DatabaseConf stores database configurations.
func (DatabaseConf) DBOpen ¶
func (c DatabaseConf) DBOpen(opts ...gorm.Option) (db *gorm.DB)
Open initialize db session based on dialer
func (DatabaseConf) GetDSN ¶
func (c DatabaseConf) GetDSN() string
GetDSN returns DSN according to the database type.
func (DatabaseConf) GetLogger ¶
func (c DatabaseConf) GetLogger() logger.Interface
func (DatabaseConf) NewCacheDriver
deprecated
func (c DatabaseConf) NewCacheDriver(redisConf redis2.RedisConf) *gorm.DB
Deprecated: NewCacheDriver returns a Gorm driver with cache. 不太稳定,不建议使用
func (DatabaseConf) NewDriver ¶
func (c DatabaseConf) NewDriver() (db *gorm.DB)
NewDriver returns a Gorm driver without cache.
func (DatabaseConf) PostgresDSN ¶
func (c DatabaseConf) PostgresDSN() string
PostgresDSN returns Postgres DSN.
func (DatabaseConf) SqliteDSN ¶
func (c DatabaseConf) SqliteDSN() string
SqliteDSN returns Sqlite DSN.
type DatabaseLogger ¶
DatabaseLogger 日志记录器
func NewDatabaseLogger ¶
func NewDatabaseLogger(logLevel logger.LogLevel, slowThreshold time.Duration) *DatabaseLogger
NewDatabaseLogger 新建日志记录器
func (*DatabaseLogger) Error ¶
func (l *DatabaseLogger) Error(ctx context.Context, msg string, data ...interface{})
Error Error日志记录
func (*DatabaseLogger) Info ¶
func (l *DatabaseLogger) Info(ctx context.Context, msg string, data ...interface{})
Info Info日志记录
func (*DatabaseLogger) LogMode ¶
func (l *DatabaseLogger) LogMode(level logger.LogLevel) logger.Interface
LogMode 设置日志记录模式
Click to show internal directories.
Click to hide internal directories.