From 83fd5c0f91fc0395af62887e701fcc3c7cd38a64 Mon Sep 17 00:00:00 2001 From: windha Date: Wed, 4 Aug 2021 12:08:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9condetion=20=E6=8B=BC?= =?UTF-8?q?=E5=86=99=E9=94=99=E8=AF=AF=EF=BC=8C=E6=94=B9=E6=88=90condition?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- README_zh_cn.md | 2 +- data/view/genfunc/def.go | 16 ++++++++-------- data/view/genfunc/genfunc_test.go | 18 +++++++++--------- data/view/genfunc/model/gen.base.go | 16 ++++++++-------- 5 files changed, 27 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 0069f14..3a167df 100644 --- a/README.md +++ b/README.md @@ -113,7 +113,7 @@ Flags: - UNIQUE_INDEX Like INDEX, create unique index - Support foreign key related properties [Support export gorm.model>>>](doc/export.md) - Support function export (foreign key, association, index , unique and more)[Support export function >>>](https://github.com/xxjwxc/gormt/blob/master/data/view/genfunc/genfunc_test.go) -- model.Condetion{} sql link +- model.Condition{} sql link ### You can enrich data types in [def](data/view/cnf/def.go) diff --git a/README_zh_cn.md b/README_zh_cn.md index b99a87b..1bf2094 100644 --- a/README_zh_cn.md +++ b/README_zh_cn.md @@ -123,7 +123,7 @@ Flags: - 支持外键相关属性 [简单带外键模式导出>>>](https://github.com/xxjwxc/gormt/tree/master/doc/export_cn.md) - 支持函数导出(包括:外键,关联体,索引关...)[简单函数导出示例>>>](https://github.com/xxjwxc/gormt/blob/master/data/view/genfunc/genfunc_test.go) - 支持默认值default -- model.Condetion{} sql拼接 +- model.Condition{} sql拼接 ### 您可以在这里丰富数据映射类型 [def](data/view/cnf/def.go) 。 diff --git a/data/view/genfunc/def.go b/data/view/genfunc/def.go index 54c47e6..2affb19 100755 --- a/data/view/genfunc/def.go +++ b/data/view/genfunc/def.go @@ -112,13 +112,13 @@ func CloseRelated() { // 自定义sql查询 -type Condetion struct { - list []*condetionInfo +type Condition struct { + list []*conditionInfo } // And a condition by and .and 一个条件 -func (c *Condetion) And(column string, cases string, value ...interface{}) { - c.list = append(c.list, &condetionInfo{ +func (c *Condition) And(column string, cases string, value ...interface{}) { + c.list = append(c.list, &conditionInfo{ andor: "and", column: column, // 列名 case_: cases, // 条件(and,or,in,>=,<=) @@ -127,8 +127,8 @@ func (c *Condetion) And(column string, cases string, value ...interface{}) { } // Or a condition by or .or 一个条件 -func (c *Condetion) Or(column string, cases string, value ...interface{}) { - c.list = append(c.list, &condetionInfo{ +func (c *Condition) Or(column string, cases string, value ...interface{}) { + c.list = append(c.list, &conditionInfo{ andor: "or", column: column, // 列名 case_: cases, // 条件(and,or,in,>=,<=) @@ -136,7 +136,7 @@ func (c *Condetion) Or(column string, cases string, value ...interface{}) { }) } -func (c *Condetion) Get() (where string, out []interface{}) { +func (c *Condition) Get() (where string, out []interface{}) { firstAnd := -1 for i := 0; i < len(c.list); i++ { // 查找第一个and if c.list[i].andor == "and" { @@ -163,7 +163,7 @@ func (c *Condetion) Get() (where string, out []interface{}) { return } -type condetionInfo struct { +type conditionInfo struct { andor string column string // 列名 case_ string // 条件(in,>=,<=) diff --git a/data/view/genfunc/genfunc_test.go b/data/view/genfunc/genfunc_test.go index 7ecd7ac..a2f971e 100644 --- a/data/view/genfunc/genfunc_test.go +++ b/data/view/genfunc/genfunc_test.go @@ -138,14 +138,14 @@ func TestFuncFetchBy(t *testing.T) { fmt.Println(accounts) } -// TestCondetion 测试sql构建 -func TestCondetion(t *testing.T) { - condetion := model.Condetion{} - condetion.And(model.AccountColumns.AccountID, ">=", "1") - condetion.And(model.AccountColumns.UserID, "in", "1", "2", "3") - condetion.Or(model.AccountColumns.Type, "in", "1", "2", "3") - - where, obj := condetion.Get() +// TestCondition 测试sql构建 +func TestCondition(t *testing.T) { + condition := model.Condition{} + condition.And(model.AccountColumns.AccountID, ">=", "1") + condition.And(model.AccountColumns.UserID, "in", "1", "2", "3") + condition.Or(model.AccountColumns.Type, "in", "1", "2", "3") + + where, obj := condition.Get() fmt.Println(where) fmt.Println(obj...) @@ -155,6 +155,6 @@ func TestCondetion(t *testing.T) { sqldb.Close() }() - accountMgr := model.AccountMgr(db.Where(condetion.Get())) + accountMgr := model.AccountMgr(db.Where(condition.Get())) accountMgr.Gets() } diff --git a/data/view/genfunc/model/gen.base.go b/data/view/genfunc/model/gen.base.go index 33ece45..8205c9e 100644 --- a/data/view/genfunc/model/gen.base.go +++ b/data/view/genfunc/model/gen.base.go @@ -93,13 +93,13 @@ func CloseRelated() { } // 自定义sql查询 -type Condetion struct { - list []*condetionInfo +type Condition struct { + list []*conditionInfo } // And a condition by and .and 一个条件 -func (c *Condetion) And(column string, cases string, value ...interface{}) { - c.list = append(c.list, &condetionInfo{ +func (c *Condition) And(column string, cases string, value ...interface{}) { + c.list = append(c.list, &conditionInfo{ andor: "and", column: column, // 列名 case_: cases, // 条件(and,or,in,>=,<=) @@ -108,8 +108,8 @@ func (c *Condetion) And(column string, cases string, value ...interface{}) { } // Or a condition by or .or 一个条件 -func (c *Condetion) Or(column string, cases string, value ...interface{}) { - c.list = append(c.list, &condetionInfo{ +func (c *Condition) Or(column string, cases string, value ...interface{}) { + c.list = append(c.list, &conditionInfo{ andor: "or", column: column, // 列名 case_: cases, // 条件(and,or,in,>=,<=) @@ -117,7 +117,7 @@ func (c *Condetion) Or(column string, cases string, value ...interface{}) { }) } -func (c *Condetion) Get() (where string, out []interface{}) { +func (c *Condition) Get() (where string, out []interface{}) { firstAnd := -1 for i := 0; i < len(c.list); i++ { // 查找第一个and if c.list[i].andor == "and" { @@ -144,7 +144,7 @@ func (c *Condetion) Get() (where string, out []interface{}) { return } -type condetionInfo struct { +type conditionInfo struct { andor string column string // 列名 case_ string // 条件(in,>=,<=)