This commit is contained in:
xxj
2021-06-13 21:56:36 +08:00
8 changed files with 12 additions and 12 deletions

View File

@@ -263,8 +263,8 @@ func (obj *_{{$obj.StructName}}Mgr) GetBatchFrom{{$oem.ColStructName}}({{CapLowe
}
{{end}}
//////////////////////////primary index case ////////////////////////////////////////////
{{range $ofm := $obj.Primay}}
// {{GenFListIndex $ofm 1}} primay or index 获取唯一内容
{{range $ofm := $obj.Primary}}
// {{GenFListIndex $ofm 1}} primary or index 获取唯一内容
func (obj *_{{$obj.StructName}}Mgr) {{GenFListIndex $ofm 1}}({{GenFListIndex $ofm 2}}) (result {{$obj.StructName}}, err error) {
err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Where("{{GenFListIndex $ofm 3}}", {{GenFListIndex $ofm 4}}).Find(&result).Error
{{GenPreloadList $obj.PreloadList false}}

View File

@@ -125,7 +125,7 @@ func TestFuncFetchBy(t *testing.T) {
accountMgr := model.AccountMgr(db)
accountMgr.SetIsRelated(true) // 打开预加载 (外键)
account, err := accountMgr.FetchByPrimaryKey(2) // primay key
account, err := accountMgr.FetchByPrimaryKey(2) // primary key
fmt.Println(err)
fmt.Println(account)

View File

@@ -276,7 +276,7 @@ func (obj *_AccountMgr) GetBatchFromName(names []string) (results []*Account, er
//////////////////////////primary index case ////////////////////////////////////////////
// FetchByPrimaryKey primay or index 获取唯一内容
// FetchByPrimaryKey primary or index 获取唯一内容
func (obj *_AccountMgr) FetchByPrimaryKey(id int) (result Account, err error) {
err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Where("`id` = ?", id).Find(&result).Error
if err == nil && obj.isRelated {
@@ -290,7 +290,7 @@ func (obj *_AccountMgr) FetchByPrimaryKey(id int) (result Account, err error) {
return
}
// FetchUniqueIndexByAccount primay or index 获取唯一内容
// FetchUniqueIndexByAccount primary or index 获取唯一内容
func (obj *_AccountMgr) FetchUniqueIndexByAccount(accountID int, userID int) (result Account, err error) {
err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Where("`account_id` = ? AND `user_id` = ?", accountID, userID).Find(&result).Error
if err == nil && obj.isRelated {

View File

@@ -148,7 +148,7 @@ func (obj *_UserMgr) GetBatchFromJob(jobs []int) (results []*User, err error) {
//////////////////////////primary index case ////////////////////////////////////////////
// FetchByPrimaryKey primay or index 获取唯一内容
// FetchByPrimaryKey primary or index 获取唯一内容
func (obj *_UserMgr) FetchByPrimaryKey(userID int) (result User, err error) {
err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Where("`user_id` = ?", userID).Find(&result).Error