Merge pull request #1 from windha/hotfix/20210804

修改condetion 拼写错误,改成condition
master
windha 3 years ago committed by GitHub
commit fa354caa7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -113,7 +113,7 @@ Flags:
- UNIQUE_INDEX Like INDEX, create unique index - UNIQUE_INDEX Like INDEX, create unique index
- Support foreign key related properties [Support export gorm.model>>>](doc/export.md) - 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) - 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) ### You can enrich data types in [def](data/view/cnf/def.go)

@ -123,7 +123,7 @@ Flags:
- 支持外键相关属性 [简单带外键模式导出>>>](https://github.com/xxjwxc/gormt/tree/master/doc/export_cn.md) - 支持外键相关属性 [简单带外键模式导出>>>](https://github.com/xxjwxc/gormt/tree/master/doc/export_cn.md)
- 支持函数导出(包括:外键,关联体,索引关...)[简单函数导出示例>>>](https://github.com/xxjwxc/gormt/blob/master/data/view/genfunc/genfunc_test.go) - 支持函数导出(包括:外键,关联体,索引关...)[简单函数导出示例>>>](https://github.com/xxjwxc/gormt/blob/master/data/view/genfunc/genfunc_test.go)
- 支持默认值default - 支持默认值default
- model.Condetion{} sql拼接 - model.Condition{} sql拼接
### 您可以在这里丰富数据映射类型 [def](data/view/cnf/def.go) 。 ### 您可以在这里丰富数据映射类型 [def](data/view/cnf/def.go) 。

@ -112,13 +112,13 @@ func CloseRelated() {
// 自定义sql查询 // 自定义sql查询
type Condetion struct { type Condition struct {
list []*condetionInfo list []*conditionInfo
} }
// And a condition by and .and 一个条件 // And a condition by and .and 一个条件
func (c *Condetion) And(column string, cases string, value ...interface{}) { func (c *Condition) And(column string, cases string, value ...interface{}) {
c.list = append(c.list, &condetionInfo{ c.list = append(c.list, &conditionInfo{
andor: "and", andor: "and",
column: column, // 列名 column: column, // 列名
case_: cases, // 条件(and,or,in,>=,<=) 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 一个条件 // Or a condition by or .or 一个条件
func (c *Condetion) Or(column string, cases string, value ...interface{}) { func (c *Condition) Or(column string, cases string, value ...interface{}) {
c.list = append(c.list, &condetionInfo{ c.list = append(c.list, &conditionInfo{
andor: "or", andor: "or",
column: column, // 列名 column: column, // 列名
case_: cases, // 条件(and,or,in,>=,<=) 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 firstAnd := -1
for i := 0; i < len(c.list); i++ { // 查找第一个and for i := 0; i < len(c.list); i++ { // 查找第一个and
if c.list[i].andor == "and" { if c.list[i].andor == "and" {
@ -163,7 +163,7 @@ func (c *Condetion) Get() (where string, out []interface{}) {
return return
} }
type condetionInfo struct { type conditionInfo struct {
andor string andor string
column string // 列名 column string // 列名
case_ string // 条件(in,>=,<=) case_ string // 条件(in,>=,<=)

@ -138,14 +138,14 @@ func TestFuncFetchBy(t *testing.T) {
fmt.Println(accounts) fmt.Println(accounts)
} }
// TestCondetion 测试sql构建 // TestCondition 测试sql构建
func TestCondetion(t *testing.T) { func TestCondition(t *testing.T) {
condetion := model.Condetion{} condition := model.Condition{}
condetion.And(model.AccountColumns.AccountID, ">=", "1") condition.And(model.AccountColumns.AccountID, ">=", "1")
condetion.And(model.AccountColumns.UserID, "in", "1", "2", "3") condition.And(model.AccountColumns.UserID, "in", "1", "2", "3")
condetion.Or(model.AccountColumns.Type, "in", "1", "2", "3") condition.Or(model.AccountColumns.Type, "in", "1", "2", "3")
where, obj := condetion.Get() where, obj := condition.Get()
fmt.Println(where) fmt.Println(where)
fmt.Println(obj...) fmt.Println(obj...)
@ -155,6 +155,6 @@ func TestCondetion(t *testing.T) {
sqldb.Close() sqldb.Close()
}() }()
accountMgr := model.AccountMgr(db.Where(condetion.Get())) accountMgr := model.AccountMgr(db.Where(condition.Get()))
accountMgr.Gets() accountMgr.Gets()
} }

@ -93,13 +93,13 @@ func CloseRelated() {
} }
// 自定义sql查询 // 自定义sql查询
type Condetion struct { type Condition struct {
list []*condetionInfo list []*conditionInfo
} }
// And a condition by and .and 一个条件 // And a condition by and .and 一个条件
func (c *Condetion) And(column string, cases string, value ...interface{}) { func (c *Condition) And(column string, cases string, value ...interface{}) {
c.list = append(c.list, &condetionInfo{ c.list = append(c.list, &conditionInfo{
andor: "and", andor: "and",
column: column, // 列名 column: column, // 列名
case_: cases, // 条件(and,or,in,>=,<=) 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 一个条件 // Or a condition by or .or 一个条件
func (c *Condetion) Or(column string, cases string, value ...interface{}) { func (c *Condition) Or(column string, cases string, value ...interface{}) {
c.list = append(c.list, &condetionInfo{ c.list = append(c.list, &conditionInfo{
andor: "or", andor: "or",
column: column, // 列名 column: column, // 列名
case_: cases, // 条件(and,or,in,>=,<=) 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 firstAnd := -1
for i := 0; i < len(c.list); i++ { // 查找第一个and for i := 0; i < len(c.list); i++ { // 查找第一个and
if c.list[i].andor == "and" { if c.list[i].andor == "and" {
@ -144,7 +144,7 @@ func (c *Condetion) Get() (where string, out []interface{}) {
return return
} }
type condetionInfo struct { type conditionInfo struct {
andor string andor string
column string // 列名 column string // 列名
case_ string // 条件(in,>=,<=) case_ string // 条件(in,>=,<=)

Loading…
Cancel
Save