@@ -121,8 +121,8 @@ type Condition struct {
|
|||||||
list []*conditionInfo
|
list []*conditionInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
// And a condition by and .and 一个条件
|
func (c *Condition) AndWithCondition(condition bool,column string, cases string, value interface{}) (*Condition) {
|
||||||
func (c *Condition) And(column string, cases string, value interface{}) {
|
if condition {
|
||||||
c.list = append(c.list, &conditionInfo{
|
c.list = append(c.list, &conditionInfo{
|
||||||
andor: "and",
|
andor: "and",
|
||||||
column: column, // 列名
|
column: column, // 列名
|
||||||
@@ -130,9 +130,18 @@ func (c *Condition) And(column string, cases string, value interface{}) {
|
|||||||
value: value,
|
value: value,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
// Or a condition by or .or 一个条件
|
|
||||||
func (c *Condition) Or(column string, cases string, value interface{}) {
|
// And a Condition by and .and 一个条件
|
||||||
|
func (c *Condition) And(column string, cases string, value interface{}) (*Condition) {
|
||||||
|
return c.AndWithCondition(true,column,cases,value)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func (c *Condition) OrWithCondition(condition bool,column string, cases string, value interface{}) (*Condition) {
|
||||||
|
if condition {
|
||||||
c.list = append(c.list, &conditionInfo{
|
c.list = append(c.list, &conditionInfo{
|
||||||
andor: "or",
|
andor: "or",
|
||||||
column: column, // 列名
|
column: column, // 列名
|
||||||
@@ -140,6 +149,13 @@ func (c *Condition) Or(column string, cases string, value interface{}) {
|
|||||||
value: value,
|
value: value,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
// Or a Condition by or .or 一个条件
|
||||||
|
func (c *Condition) Or(column string, cases string, value interface{}) (*Condition) {
|
||||||
|
return c.OrWithCondition(true,column,cases,value)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Condition) Get() (where string, out []interface{}) {
|
func (c *Condition) Get() (where string, out []interface{}) {
|
||||||
firstAnd := -1
|
firstAnd := -1
|
||||||
|
|||||||
@@ -143,6 +143,7 @@ func TestCondition(t *testing.T) {
|
|||||||
condition := model.Condition{}
|
condition := model.Condition{}
|
||||||
condition.And(model.AccountColumns.AccountID, ">=", "1")
|
condition.And(model.AccountColumns.AccountID, ">=", "1")
|
||||||
condition.And(model.AccountColumns.UserID, "in", []string{"1", "2", "3"})
|
condition.And(model.AccountColumns.UserID, "in", []string{"1", "2", "3"})
|
||||||
|
condition.AndWithCondition(false, model.AccountColumns.AccountID, "in", []string{"5"})
|
||||||
condition.Or(model.AccountColumns.Type, "in", []string{"1", "2", "3"})
|
condition.Or(model.AccountColumns.Type, "in", []string{"1", "2", "3"})
|
||||||
|
|
||||||
where, obj := condition.Get()
|
where, obj := condition.Get()
|
||||||
@@ -155,6 +156,6 @@ func TestCondition(t *testing.T) {
|
|||||||
sqldb.Close()
|
sqldb.Close()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
accountMgr := model.AccountMgr(db.Where(condition.Get()))
|
accountMgr := model.AccountMgr(db.Where(where, obj...))
|
||||||
accountMgr.Gets()
|
accountMgr.Gets()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,8 +97,8 @@ type Condition struct {
|
|||||||
list []*conditionInfo
|
list []*conditionInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
// And a condition by and .and 一个条件
|
func (c *Condition) AndWithCondition(condition bool, column string, cases string, value interface{}) (*Condition) {
|
||||||
func (c *Condition) And(column string, cases string, value interface{}) {
|
if condition {
|
||||||
c.list = append(c.list, &conditionInfo{
|
c.list = append(c.list, &conditionInfo{
|
||||||
andor: "and",
|
andor: "and",
|
||||||
column: column, // 列名
|
column: column, // 列名
|
||||||
@@ -106,9 +106,16 @@ func (c *Condition) And(column string, cases string, value interface{}) {
|
|||||||
value: value,
|
value: value,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
// Or a condition by or .or 一个条件
|
// And a Condition by and .and 一个条件
|
||||||
func (c *Condition) Or(column string, cases string, value interface{}) {
|
func (c *Condition) And(column string, cases string, value interface{})(*Condition) {
|
||||||
|
return c.AndWithCondition(true, column, cases, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Condition) OrWithCondition(condition bool, column string, cases string, value interface{}) (*Condition){
|
||||||
|
if condition {
|
||||||
c.list = append(c.list, &conditionInfo{
|
c.list = append(c.list, &conditionInfo{
|
||||||
andor: "or",
|
andor: "or",
|
||||||
column: column, // 列名
|
column: column, // 列名
|
||||||
@@ -116,6 +123,13 @@ func (c *Condition) Or(column string, cases string, value interface{}) {
|
|||||||
value: value,
|
value: value,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
// Or a Condition by or .or 一个条件
|
||||||
|
func (c *Condition) Or(column string, cases string, value interface{})(*Condition) {
|
||||||
|
return c.OrWithCondition(true, column, cases, value)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Condition) Get() (where string, out []interface{}) {
|
func (c *Condition) Get() (where string, out []interface{}) {
|
||||||
firstAnd := -1
|
firstAnd := -1
|
||||||
|
|||||||
Reference in New Issue
Block a user