add multi unique support
添加多个unique index支持,调整unique接口名。 FetchUniqueBy[xxx]
This commit is contained in:
@@ -195,7 +195,7 @@ func widthFunctionName(info FList) string {
|
|||||||
case ColumnsKeyPrimary: // primary key.主键
|
case ColumnsKeyPrimary: // primary key.主键
|
||||||
return "FetchByPrimaryKey"
|
return "FetchByPrimaryKey"
|
||||||
case ColumnsKeyUnique: // unique key.唯一索引
|
case ColumnsKeyUnique: // unique key.唯一索引
|
||||||
return "FetchByUnique"
|
return "FetchUniqueBy" + getCamelName(info.KeyName)
|
||||||
case ColumnsKeyIndex: // index key.复合索引
|
case ColumnsKeyIndex: // index key.复合索引
|
||||||
return "FetchIndexBy" + getCamelName(info.KeyName)
|
return "FetchIndexBy" + getCamelName(info.KeyName)
|
||||||
case ColumnsKeyUniqueIndex: // unique index key.唯一复合索引
|
case ColumnsKeyUniqueIndex: // unique index key.唯一复合索引
|
||||||
@@ -204,3 +204,7 @@ func widthFunctionName(info FList) string {
|
|||||||
|
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func fixNotes(str string) string { // 注释
|
||||||
|
return strings.Replace(str, "\n", "\n//", -1)
|
||||||
|
}
|
||||||
|
|||||||
@@ -228,7 +228,7 @@ func (m *_Model) generateFunc() (genOut []GenOutInfo) {
|
|||||||
for _, tab := range m.info.TabList {
|
for _, tab := range m.info.TabList {
|
||||||
var pkg genstruct.GenPackage
|
var pkg genstruct.GenPackage
|
||||||
pkg.SetPackage(m.info.PackageName) //package name
|
pkg.SetPackage(m.info.PackageName) //package name
|
||||||
pkg.AddImport(`"github.com/jinzhu/gorm"`)
|
pkg.AddImport(cnf.EImportsHead["gorm.Model"])
|
||||||
pkg.AddImport(`"fmt"`)
|
pkg.AddImport(`"fmt"`)
|
||||||
|
|
||||||
data := funDef{
|
data := funDef{
|
||||||
@@ -265,7 +265,7 @@ func (m *_Model) generateFunc() (genOut []GenOutInfo) {
|
|||||||
|
|
||||||
data.Em = append(data.Em, EmInfo{
|
data.Em = append(data.Em, EmInfo{
|
||||||
IsMulti: isMulti,
|
IsMulti: isMulti,
|
||||||
Notes: el.Notes,
|
Notes: fixNotes(el.Notes),
|
||||||
Type: typeName, // Type.类型标记
|
Type: typeName, // Type.类型标记
|
||||||
ColName: el.Name,
|
ColName: el.Name,
|
||||||
ColStructName: getCamelName(el.Name),
|
ColStructName: getCamelName(el.Name),
|
||||||
@@ -283,7 +283,7 @@ func (m *_Model) generateFunc() (genOut []GenOutInfo) {
|
|||||||
if isFind {
|
if isFind {
|
||||||
var info PreloadInfo
|
var info PreloadInfo
|
||||||
info.IsMulti = isMulti
|
info.IsMulti = isMulti
|
||||||
info.Notes = notes
|
info.Notes = fixNotes(notes)
|
||||||
info.ForeignkeyTableName = v.TableName
|
info.ForeignkeyTableName = v.TableName
|
||||||
info.ForeignkeyCol = v.ColumnName
|
info.ForeignkeyCol = v.ColumnName
|
||||||
info.ForeignkeyStructName = getCamelName(v.TableName)
|
info.ForeignkeyStructName = getCamelName(v.TableName)
|
||||||
|
|||||||
@@ -57,6 +57,6 @@
|
|||||||
### Index access
|
### Index access
|
||||||
|
|
||||||
`FetchByPrimaryKey` : Primary key acquisition
|
`FetchByPrimaryKey` : Primary key acquisition
|
||||||
`FetchByUnique` : Get by unique index
|
`FetchUniqueBy[xxx]` : Get by unique index
|
||||||
`FetchIndexBy[xxx]` : Composite index fetch (multiple returned)
|
`FetchIndexBy[xxx]` : Composite index fetch (multiple returned)
|
||||||
`FetchUniqueIndexBy[xxx]` : Unique composite index fetch (return one)
|
`FetchUniqueIndexBy[xxx]` : Unique composite index fetch (return one)
|
||||||
@@ -53,6 +53,6 @@
|
|||||||
|
|
||||||
### 索引方式获取
|
### 索引方式获取
|
||||||
`FetchByPrimaryKey` : 主键获取
|
`FetchByPrimaryKey` : 主键获取
|
||||||
`FetchByUnique` : 唯一索引方式获取
|
`FetchUniqueBy[xxx]` : 唯一索引方式获取
|
||||||
`FetchIndexBy[xxx]` : 复合索引获取(返回多个)
|
`FetchIndexBy[xxx]` : 复合索引获取(返回多个)
|
||||||
`FetchUniqueIndexBy[xxx]` : 唯一复合索引获取(返回一个)
|
`FetchUniqueIndexBy[xxx]` : 唯一复合索引获取(返回一个)
|
||||||
Reference in New Issue
Block a user