day day up
This commit is contained in:
@@ -46,4 +46,23 @@ func (f optionFunc) apply(o *options) {
|
||||
f(o)
|
||||
}
|
||||
`
|
||||
|
||||
genlogic = `{{$obj := .}}{{$list := $obj.Em}}
|
||||
type _{{$obj.StructName}}Mgr struct {
|
||||
*_BaseMgr
|
||||
}
|
||||
|
||||
// {{$obj.StructName}}Mgr open func
|
||||
func {{$obj.StructName}}Mgr(db *gorm.DB) *_{{$obj.StructName}}Mgr {
|
||||
if db == nil {
|
||||
panic(fmt.Errorf("{{$obj.StructName}}Mgr init need db"))
|
||||
}
|
||||
return &_{{$obj.StructName}}Mgr{_BaseMgr: &_BaseMgr{DB: db}}
|
||||
}
|
||||
|
||||
// GetTableName get sql table name.获取数据库名字
|
||||
func (obj *_{{$obj.StructName}}Mgr) GetTableName() string {
|
||||
return "{{$obj.TableName}}"
|
||||
}
|
||||
`
|
||||
)
|
||||
|
||||
@@ -147,6 +147,7 @@ func (obj *_ExampleMgr) GetByOptions(opts ...Option) (results []*Example, err er
|
||||
}
|
||||
|
||||
err = obj.DB.Table(obj.GetTableName()).Where(options.query).Find(&results).Error
|
||||
|
||||
if err == nil && obj.isRelated {
|
||||
for i := 0; i < len(results); i++ {
|
||||
var userList []User
|
||||
@@ -162,9 +163,7 @@ func (obj *_ExampleMgr) GetByOptions(opts ...Option) (results []*Example, err er
|
||||
|
||||
// WithID id获取
|
||||
func (obj *_ExampleMgr) WithID(id int64) Option {
|
||||
return optionFunc(func(o *options) {
|
||||
o.query["id"] = id
|
||||
})
|
||||
return optionFunc(func(o *options) { o.query["id"] = id })
|
||||
}
|
||||
|
||||
func (obj *_ExampleMgr) WithUserID(id int64) Option {
|
||||
|
||||
@@ -7,5 +7,5 @@ func GetGenBaseTemp() string {
|
||||
|
||||
// GetGenLogicTemp get gen logic template str
|
||||
func GetGenLogicTemp() string {
|
||||
return ""
|
||||
return genlogic
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user