From 19b39a0b41181c37032b1999d1684e16d7e0ee59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=A2=E5=B0=8F=E5=86=9B?= <346944475@qq.com> Date: Tue, 16 Jun 2020 17:51:58 +0800 Subject: [PATCH] add multi unique support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加多个unique index支持,调整unique接口名。 FetchUniqueBy[xxx] --- data/view/model/common.go | 6 +++++- data/view/model/model.go | 6 +++--- doc/func.md | 2 +- doc/func_cn.md | 2 +- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/data/view/model/common.go b/data/view/model/common.go index ff1ae60..e92f849 100644 --- a/data/view/model/common.go +++ b/data/view/model/common.go @@ -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.唯一复合索引 @@ -204,3 +204,7 @@ func widthFunctionName(info FList) string { return "" } + +func fixNotes(str string) string { // 注释 + return strings.Replace(str, "\n", "\n//", -1) +} diff --git a/data/view/model/model.go b/data/view/model/model.go index 2d899c1..2ae9a11 100644 --- a/data/view/model/model.go +++ b/data/view/model/model.go @@ -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{ @@ -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), @@ -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) diff --git a/doc/func.md b/doc/func.md index caca622..3c8550c 100644 --- a/doc/func.md +++ b/doc/func.md @@ -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) \ No newline at end of file diff --git a/doc/func_cn.md b/doc/func_cn.md index 8f97e05..7f5934e 100644 --- a/doc/func_cn.md +++ b/doc/func_cn.md @@ -53,6 +53,6 @@ ### 索引方式获取 `FetchByPrimaryKey` : 主键获取 - `FetchByUnique` : 唯一索引方式获取 + `FetchUniqueBy[xxx]` : 唯一索引方式获取 `FetchIndexBy[xxx]` : 复合索引获取(返回多个) `FetchUniqueIndexBy[xxx]` : 唯一复合索引获取(返回一个) \ No newline at end of file