Merge branch 'master' of https://github.com/xxjwxc/gormt
This commit is contained in:
@@ -162,7 +162,7 @@ type UserAccountTbl struct {
|
|||||||
## 6. support func export
|
## 6. support func export
|
||||||
### The exported function is only the auxiliary class function of Gorm, and calls Gorm completely
|
### The exported function is only the auxiliary class function of Gorm, and calls Gorm completely
|
||||||
```
|
```
|
||||||
// FetchByPrimaryKey primay or index 获取唯一内容
|
// FetchByPrimaryKey primary or index 获取唯一内容
|
||||||
func (obj *_UserAccountTblMgr) FetchByPrimaryKey(ID int) (result UserAccountTbl, err error) {
|
func (obj *_UserAccountTblMgr) FetchByPrimaryKey(ID int) (result UserAccountTbl, err error) {
|
||||||
err = obj.DB.Table(obj.GetTableName()).Where("id = ?", ID).Find(&result).Error
|
err = obj.DB.Table(obj.GetTableName()).Where("id = ?", ID).Find(&result).Error
|
||||||
if err == nil && obj.isRelated {
|
if err == nil && obj.isRelated {
|
||||||
|
|||||||
@@ -171,7 +171,7 @@ type UserAccountTbl struct {
|
|||||||
## 6. 支持函数导出(导出函数只是 gorm 的辅助类函数,完全兼调用 gorm)
|
## 6. 支持函数导出(导出函数只是 gorm 的辅助类函数,完全兼调用 gorm)
|
||||||
|
|
||||||
```
|
```
|
||||||
// FetchByPrimaryKey primay or index 获取唯一内容
|
// FetchByPrimaryKey primary or index 获取唯一内容
|
||||||
func (obj *_UserAccountTblMgr) FetchByPrimaryKey(ID int) (result UserAccountTbl, err error) {
|
func (obj *_UserAccountTblMgr) FetchByPrimaryKey(ID int) (result UserAccountTbl, err error) {
|
||||||
err = obj.DB.Table(obj.GetTableName()).Where("id = ?", ID).Find(&result).Error
|
err = obj.DB.Table(obj.GetTableName()).Where("id = ?", ID).Find(&result).Error
|
||||||
if err == nil && obj.isRelated {
|
if err == nil && obj.isRelated {
|
||||||
|
|||||||
@@ -263,8 +263,8 @@ func (obj *_{{$obj.StructName}}Mgr) GetBatchFrom{{$oem.ColStructName}}({{CapLowe
|
|||||||
}
|
}
|
||||||
{{end}}
|
{{end}}
|
||||||
//////////////////////////primary index case ////////////////////////////////////////////
|
//////////////////////////primary index case ////////////////////////////////////////////
|
||||||
{{range $ofm := $obj.Primay}}
|
{{range $ofm := $obj.Primary}}
|
||||||
// {{GenFListIndex $ofm 1}} primay or index 获取唯一内容
|
// {{GenFListIndex $ofm 1}} primary or index 获取唯一内容
|
||||||
func (obj *_{{$obj.StructName}}Mgr) {{GenFListIndex $ofm 1}}({{GenFListIndex $ofm 2}}) (result {{$obj.StructName}}, err error) {
|
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
|
err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Where("{{GenFListIndex $ofm 3}}", {{GenFListIndex $ofm 4}}).Find(&result).Error
|
||||||
{{GenPreloadList $obj.PreloadList false}}
|
{{GenPreloadList $obj.PreloadList false}}
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ func TestFuncFetchBy(t *testing.T) {
|
|||||||
accountMgr := model.AccountMgr(db)
|
accountMgr := model.AccountMgr(db)
|
||||||
accountMgr.SetIsRelated(true) // 打开预加载 (外键)
|
accountMgr.SetIsRelated(true) // 打开预加载 (外键)
|
||||||
|
|
||||||
account, err := accountMgr.FetchByPrimaryKey(2) // primay key
|
account, err := accountMgr.FetchByPrimaryKey(2) // primary key
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
fmt.Println(account)
|
fmt.Println(account)
|
||||||
|
|
||||||
|
|||||||
@@ -276,7 +276,7 @@ func (obj *_AccountMgr) GetBatchFromName(names []string) (results []*Account, er
|
|||||||
|
|
||||||
//////////////////////////primary index case ////////////////////////////////////////////
|
//////////////////////////primary index case ////////////////////////////////////////////
|
||||||
|
|
||||||
// FetchByPrimaryKey primay or index 获取唯一内容
|
// FetchByPrimaryKey primary or index 获取唯一内容
|
||||||
func (obj *_AccountMgr) FetchByPrimaryKey(id int) (result Account, err error) {
|
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
|
err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Where("`id` = ?", id).Find(&result).Error
|
||||||
if err == nil && obj.isRelated {
|
if err == nil && obj.isRelated {
|
||||||
@@ -290,7 +290,7 @@ func (obj *_AccountMgr) FetchByPrimaryKey(id int) (result Account, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// FetchUniqueIndexByAccount primay or index 获取唯一内容
|
// FetchUniqueIndexByAccount primary or index 获取唯一内容
|
||||||
func (obj *_AccountMgr) FetchUniqueIndexByAccount(accountID int, userID int) (result Account, err error) {
|
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
|
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 {
|
if err == nil && obj.isRelated {
|
||||||
|
|||||||
@@ -148,7 +148,7 @@ func (obj *_UserMgr) GetBatchFromJob(jobs []int) (results []*User, err error) {
|
|||||||
|
|
||||||
//////////////////////////primary index case ////////////////////////////////////////////
|
//////////////////////////primary index case ////////////////////////////////////////////
|
||||||
|
|
||||||
// FetchByPrimaryKey primay or index 获取唯一内容
|
// FetchByPrimaryKey primary or index 获取唯一内容
|
||||||
func (obj *_UserMgr) FetchByPrimaryKey(userID int) (result User, err error) {
|
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
|
err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Where("`user_id` = ?", userID).Find(&result).Error
|
||||||
|
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ type funDef struct {
|
|||||||
TableName string
|
TableName string
|
||||||
PreloadList []PreloadInfo // 外键列表,(生成关联数据)
|
PreloadList []PreloadInfo // 外键列表,(生成关联数据)
|
||||||
Em []EmInfo // index 列表
|
Em []EmInfo // index 列表
|
||||||
Primay []FList // primay unique
|
Primary []FList // primary unique
|
||||||
Index []FList // index
|
Index []FList // index
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -376,9 +376,9 @@ func (m *_Model) generateFunc() (genOut []GenOutInfo) {
|
|||||||
// ---------end--
|
// ---------end--
|
||||||
}
|
}
|
||||||
|
|
||||||
data.Primay = append(data.Primay, primary...)
|
data.Primary = append(data.Primary, primary...)
|
||||||
data.Primay = append(data.Primay, unique...)
|
data.Primary = append(data.Primary, unique...)
|
||||||
data.Primay = append(data.Primay, uniqueIndex...)
|
data.Primary = append(data.Primary, uniqueIndex...)
|
||||||
data.Index = append(data.Index, index...)
|
data.Index = append(data.Index, index...)
|
||||||
tmpl, err := template.New("gen_logic").
|
tmpl, err := template.New("gen_logic").
|
||||||
Funcs(template.FuncMap{"GenPreloadList": GenPreloadList, "GenFListIndex": GenFListIndex, "CapLowercase": CapLowercase, "GetTablePrefixName": GetTablePrefixName}).
|
Funcs(template.FuncMap{"GenPreloadList": GenPreloadList, "GenFListIndex": GenFListIndex, "CapLowercase": CapLowercase, "GetTablePrefixName": GetTablePrefixName}).
|
||||||
|
|||||||
Reference in New Issue
Block a user