Documentation
¶
Index ¶
Constants ¶
View Source
const ( DEFALUT_DB_OPTION = "charset=utf8mb4&parseTime=True&loc=Local" DEFALUT_MAX_IDLE_CONNS = 10 DEFAULT_MAX_OPEN_CONNS = 100 DEFAULT_LOG_MODE = "Info" )
Variables ¶
View Source
var (
ErrRecordNotFound = gorm.ErrRecordNotFound
)
Functions ¶
Types ¶
type Config ¶ added in v1.0.12
type Config struct { IP string `yaml:"ip"` // 服务器地址 Port string `yaml:"port"` // 端口 DB string `yaml:"db"` // 数据库名 Name string `yaml:"username"` // 数据库用户名 Password string `yaml:"password"` // 数据库密码 Option string `yaml:"option"` // 高级配置 MaxIdleConns int `yaml:"max-idle-conns"` // 空闲中的最大连接数 MaxOpenConns int `yaml:"max-open-conns"` // 打开到数据库的最大连接数 LogMode string `yaml:"log-mode"` // 是否开启Gorm全局日志 }
type SqlConn ¶
type SqlConn interface { DB() *gorm.DB Raw(sql string, values ...interface{}) *gorm.DB //TODO 携带trace相关逻辑 RawCtx(ctx context.Context, sql string, values ...interface{}) *gorm.DB Insert(val interface{}) error InsertCtx(ctx context.Context, val interface{}) error FindOne(id int64, out interface{}) error FindOneByFilter(filter map[string]interface{}, out interface{}, opts ...Option) error FindByFilter(filter map[string]interface{}, out interface{}, opts ...Option) error //更新记录,包含零值字段 Save(val interface{}) *gorm.DB //更新记录,非零值字段 Updates(val interface{}) *gorm.DB //根据条件更新记录 UpdateByFilter(model interface{}, filter map[string]interface{}, upVal map[string]interface{}) *gorm.DB //删除主键记录 Delete(model interface{}, id int64) error //根据条件删除记录 DeleteByFilter(model interface{}, filter map[string]interface{}) error }
Click to show internal directories.
Click to hide internal directories.