Skip to content

Commit

Permalink
add multi unique support
Browse files Browse the repository at this point in the history
添加多个unique index支持,调整unique接口名。
FetchUniqueBy[xxx]
  • Loading branch information
xxjwxc committed Jun 16, 2020
1 parent 2b63b9f commit 19b39a0
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
6 changes: 5 additions & 1 deletion data/view/model/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func widthFunctionName(info FList) string {
case ColumnsKeyPrimary: // primary key.主键
return "FetchByPrimaryKey"
case ColumnsKeyUnique: // unique key.唯一索引
return "FetchByUnique"
return "FetchUniqueBy" + getCamelName(info.KeyName)
case ColumnsKeyIndex: // index key.复合索引
return "FetchIndexBy" + getCamelName(info.KeyName)
case ColumnsKeyUniqueIndex: // unique index key.唯一复合索引
Expand All @@ -204,3 +204,7 @@ func widthFunctionName(info FList) string {

return ""
}

func fixNotes(str string) string { // 注释
return strings.Replace(str, "\n", "\n//", -1)
}
6 changes: 3 additions & 3 deletions data/view/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func (m *_Model) generateFunc() (genOut []GenOutInfo) {
for _, tab := range m.info.TabList {
var pkg genstruct.GenPackage
pkg.SetPackage(m.info.PackageName) //package name
pkg.AddImport(`"github.com/jinzhu/gorm"`)
pkg.AddImport(cnf.EImportsHead["gorm.Model"])
pkg.AddImport(`"fmt"`)

data := funDef{
Expand Down Expand Up @@ -265,7 +265,7 @@ func (m *_Model) generateFunc() (genOut []GenOutInfo) {

data.Em = append(data.Em, EmInfo{
IsMulti: isMulti,
Notes: el.Notes,
Notes: fixNotes(el.Notes),
Type: typeName, // Type.类型标记
ColName: el.Name,
ColStructName: getCamelName(el.Name),
Expand All @@ -283,7 +283,7 @@ func (m *_Model) generateFunc() (genOut []GenOutInfo) {
if isFind {
var info PreloadInfo
info.IsMulti = isMulti
info.Notes = notes
info.Notes = fixNotes(notes)
info.ForeignkeyTableName = v.TableName
info.ForeignkeyCol = v.ColumnName
info.ForeignkeyStructName = getCamelName(v.TableName)
Expand Down
2 changes: 1 addition & 1 deletion doc/func.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@
### Index access

`FetchByPrimaryKey` : Primary key acquisition
`FetchByUnique` : Get by unique index
`FetchUniqueBy[xxx]` : Get by unique index
`FetchIndexBy[xxx]` : Composite index fetch (multiple returned)
`FetchUniqueIndexBy[xxx]` : Unique composite index fetch (return one)
2 changes: 1 addition & 1 deletion doc/func_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@

### 索引方式获取
`FetchByPrimaryKey` : 主键获取
`FetchByUnique` : 唯一索引方式获取
`FetchUniqueBy[xxx]` : 唯一索引方式获取
`FetchIndexBy[xxx]` : 复合索引获取(返回多个)
`FetchUniqueIndexBy[xxx]` : 唯一复合索引获取(返回一个)

0 comments on commit 19b39a0

Please sign in to comment.