Documentation
¶
Index ¶
- Variables
- func Cli(ctx context.Context) *gorm.DB
- func KeywordGenerator(columnList []string, keyword string) func(db *gorm.DB) *gorm.DB
- type BasicCrud
- type BasicQuery
- type CRUDImpl
- func (c *CRUDImpl) Create(model interface{}) (err error)
- func (c *CRUDImpl) Delete(m interface{}, hardDelete bool) (err error)
- func (c *CRUDImpl) FindByCon(con, model interface{}, args ...interface{}) (err error)
- func (c *CRUDImpl) GetByID(model interface{}, id int64) (err error)
- func (c *CRUDImpl) GetList(q BasicQuery, model, list interface{}) (total int64, err error)
- func (c *CRUDImpl) GetOneByCon(con, model interface{}, args ...interface{}) (err error)
- func (c *CRUDImpl) UpdateWithMap(model interface{}, u map[string]interface{}) (err error)
- type CreateCrud
- type DB
- type DBConfig
- type DBLog
- func (d DBLog) Error(ctx context.Context, msg string, data ...interface{})
- func (d DBLog) Info(ctx context.Context, msg string, data ...interface{})
- func (d *DBLog) LogMode(level logg.LogLevel) logg.Interface
- func (d DBLog) Trace(ctx context.Context, begin time.Time, ...)
- func (d DBLog) Warn(ctx context.Context, msg string, data ...interface{})
- type DeleteCrud
- type FindByConCrud
- type GetByConCrud
- type GetByIDCrud
- type GetListCrud
- type MyNamingStrategy
- func (mns MyNamingStrategy) CheckerName(table, column string) string
- func (mns MyNamingStrategy) ColumnName(table, column string) string
- func (mns MyNamingStrategy) IndexName(table, column string) string
- func (mns MyNamingStrategy) JoinTableName(str string) string
- func (mns MyNamingStrategy) RelationshipFKName(rel schema.Relationship) string
- func (mns MyNamingStrategy) SchemaName(table string) string
- func (mns MyNamingStrategy) TableName(str string) string
- type UpdateCrud
Constants ¶
This section is empty.
Variables ¶
View Source
var (
ErrClient = errors.New("mysql client is not initialized yet")
)
Functions ¶
Types ¶
type BasicCrud ¶
type BasicCrud interface {
GetListCrud
GetByIDCrud
GetByConCrud
FindByConCrud
CreateCrud
UpdateCrud
DeleteCrud
}
type BasicQuery ¶
type BasicQuery struct {
IDList []int64 `json:"IdList"` // id数组
Fields []string `json:"Fields"` // 指定返回字段
Keyword string `json:"Keyword"` // 关键词(全局模糊搜索)
Order string `json:"Order"` // 排序,支持desc和asc
Limit int `json:"Limit"` // 分页条数
Offset int `json:"Offset"` // 分页偏移量
Query string `json:"Query"` // 自定义查询语句;使用RSQL语法
}
type CRUDImpl ¶
func (*CRUDImpl) FindByCon ¶
FindByCon conditions could be pointer of a model struct, map or string model must be a pointer
func (*CRUDImpl) GetList ¶
func (c *CRUDImpl) GetList(q BasicQuery, model, list interface{}) (total int64, err error)
GetList model and list must be a pointer
func (*CRUDImpl) GetOneByCon ¶
GetOneByCon conditions could be pointer of a model struct, map or string model must be a pointer
func (*CRUDImpl) UpdateWithMap ¶
UpdateWithMap model must be a pointer
type CreateCrud ¶
type CreateCrud interface {
Create(model interface{}) error
}
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
type DBConfig ¶
type DBConfig struct {
WriteDBHost string `yaml:"write_db_host" env:"MySQLWriteHost" env-description:"mysql master host"`
WriteDBPort uint16 `yaml:"write_db_port" env:"MySQLWritePort" env-description:"mysql master port"`
WriteDBUser string `yaml:"write_db_user" env:"MySQLWriteUser" env-description:"mysql master user"`
WriteDBPassword string `yaml:"write_db_password" env:"MySQLWritePassword" env-description:"mysql master password"`
WriteDB string `yaml:"write_db" env:"MySQLWriteDB" env-description:"mysql master database"`
ReadDBHostList []string `yaml:"read_db_host_list" env:"MySQLReadHostList" env-description:"mysql slave host list"`
ReadDBPort uint16 `yaml:"read_db_port" env:"MySQLReadPort" env-description:"mysql slave port"`
ReadDBUser string `yaml:"read_db_user" env:"MySQLReadUser" env-description:"mysql slave user"`
ReadDBPassword string `yaml:"read_db_password" env:"MySQLReadPassword" env-description:"mysql slave password"`
ReadDB string `yaml:"read_db" env:"MySQLReadDB" env-description:"mysql slave database"`
Prefix string `yaml:"table_prefix"`
MaxIdleConns int `yaml:"max_idle_conns"`
MaxOpenConns int `yaml:"max_open_conns"`
Logging bool `yaml:"logging"`
LogLevel string `yaml:"log_level" env:"MySQLLogLevel" env-description:"log level of mysql log: silent/info/warn/error"`
RawColumn bool `yaml:"-"`
}
type DeleteCrud ¶
type FindByConCrud ¶ added in v0.1.0
type FindByConCrud interface {
FindByCon(con, model interface{}, args ...interface{}) error
}
type GetByConCrud ¶ added in v0.1.0
type GetByConCrud interface {
GetOneByCon(con, model interface{}, args ...interface{}) error
}
type GetByIDCrud ¶ added in v0.1.0
type GetListCrud ¶
type GetListCrud interface {
GetList(q BasicQuery, model, list interface{}) (total int64, err error)
}
type MyNamingStrategy ¶
type MyNamingStrategy struct {
// contains filtered or unexported fields
}
MyNamingStrategy 只改了ColumnName,直接返回结构体的字段名(用于大驼峰标准)
func (MyNamingStrategy) CheckerName ¶
func (mns MyNamingStrategy) CheckerName(table, column string) string
CheckerName generate checker name
func (MyNamingStrategy) ColumnName ¶
func (mns MyNamingStrategy) ColumnName(table, column string) string
ColumnName convert string to column name
func (MyNamingStrategy) IndexName ¶
func (mns MyNamingStrategy) IndexName(table, column string) string
IndexName generate index name
func (MyNamingStrategy) JoinTableName ¶
func (mns MyNamingStrategy) JoinTableName(str string) string
JoinTableName convert string to join table name
func (MyNamingStrategy) RelationshipFKName ¶
func (mns MyNamingStrategy) RelationshipFKName(rel schema.Relationship) string
RelationshipFKName generate fk name for relation
func (MyNamingStrategy) SchemaName ¶
func (mns MyNamingStrategy) SchemaName(table string) string
func (MyNamingStrategy) TableName ¶
func (mns MyNamingStrategy) TableName(str string) string
type UpdateCrud ¶
Click to show internal directories.
Click to hide internal directories.