Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrNoInit = errors.New("eMysql: please initialize with eMysql.Init()")
Functions ¶
func GetConnect ¶
func GetConnectByConf ¶
func GetConnectByConf(conf MultipleConf) (*gorm.DB, error)
GetConnectByConf 获取gorm连接
func Init ¶
func Init(c map[string]MultipleConf, logOptions ...GormConfigOption)
Types ¶
type EGorm ¶
type EGorm struct {
ConfName string
}
EGorm 在结构体引入组合并赋值ConfName,即可通过GDB()获取gorm连接 Example
type User struct { EGorm }
var user = User{EGorm{ConfName: "localhost"}}
func (u *User) GetUser(id int64) error { u.GDB().Where("id = ?", id).First() }
type GormConfigOption ¶
type GormConfigOption func(conf *logConf)
func WithIgnoreRecordNotFound ¶
func WithIgnoreRecordNotFound(isIgnore bool) GormConfigOption
WithIgnoreRecordNotFound 是否忽略notFound错误,默认为 false
func WithSlowThreshold ¶
func WithSlowThreshold(duration time.Duration) GormConfigOption
WithSlowThreshold 慢日志时间阈值,默认为 100毫秒
type MultipleConf ¶
MultipleConf 读写分离配置
func (*MultipleConf) ConfToGormDialector ¶
func (m *MultipleConf) ConfToGormDialector() (sourcesDialector, replicasDialector []gorm.Dialector)
ConfToGormDialector 处理配置为gorm配置 @param conf 配置列表 @return sourcesDSN 写库dsn列表 @return replicasDSN 读库dsn列表
Click to show internal directories.
Click to hide internal directories.