Documentation ¶
Index ¶
- Variables
- func AutoInitGormWithConfig()
- func GetGormSingleton(name string) (gdb *gorm.DB, err error)
- func GetGormSingletonByModel(gormmodel GormModel) (gdb *gorm.DB, err error)
- func InitGorm(dbname string, cfg GormConfig) error
- type GormConfig
- type GormConnPoolConfig
- type GormLog
- func (gl *GormLog) Error(ctx context.Context, format string, args ...interface{})
- func (gl *GormLog) Info(ctx context.Context, format string, args ...interface{})
- func (gl *GormLog) LogMode(lv glog.LogLevel) glog.Interface
- func (gl *GormLog) Prefix() string
- func (gl *GormLog) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error)
- func (gl *GormLog) Warn(ctx context.Context, format string, args ...interface{})
- func (gl *GormLog) WithPrefix(prefix string) glog.Interface
- type GormLogConfig
- type GormModel
Constants ¶
This section is empty.
Variables ¶
View Source
var (
ErrDBNotFound = errors.New("the db singletons not found or not initialization")
)
Functions ¶
func AutoInitGormWithConfig ¶
func AutoInitGormWithConfig()
db, err := gorm.Open(sqlite.Open("gorm.db"), &gorm.Config{ NamingStrategy: schema.NamingStrategy{ TablePrefix: "t_", // table name prefix, table for `User` would be `t_users` SingularTable: true, // use singular table name, table for `User` would be `user` with this option enabled NoLowerCase: true, // skip the snake_casing of names NameReplacer: strings.NewReplacer("CID", "Cid"), // use name replacer to change struct/field name before convert it to db name }, })
func GetGormSingleton ¶
GetGormSingleton 获取GetGormSingleton单例
func GetGormSingletonByModel ¶
func InitGorm ¶
func InitGorm(dbname string, cfg GormConfig) error
Types ¶
type GormConfig ¶
type GormConfig struct { MysqlConfig *mysql.Config GormConfig *gorm.Config ConnPoolConfig GormConnPoolConfig }
type GormConnPoolConfig ¶
type GormLog ¶
type GormLog struct { Logger *fileLogger.FileLogger Config GormLogConfig // contains filtered or unexported fields }
type Interface interface { LogMode(LogLevel) Interface Info(context.Context, string, ...interface{}) Warn(context.Context, string, ...interface{}) Error(context.Context, string, ...interface{}) Trace(ctx context.Context, begin time.Time, fc func() (sql string, rowsAffected int64), err error) }
func NewGormLogger ¶
func NewGormLogger(config GormLogConfig) *GormLog
type GormLogConfig ¶
Click to show internal directories.
Click to hide internal directories.