@@ -121,24 +121,40 @@ type Condition struct {
|
||||
list []*conditionInfo
|
||||
}
|
||||
|
||||
// And a condition by and .and 一个条件
|
||||
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,>=,<=)
|
||||
value: value,
|
||||
})
|
||||
func (c *Condition) AndWithCondition(condition bool,column string, cases string, value interface{}) (*Condition) {
|
||||
if condition {
|
||||
c.list = append(c.list, &conditionInfo{
|
||||
andor: "and",
|
||||
column: column, // 列名
|
||||
case_: cases, // 条件(and,or,in,>=,<=)
|
||||
value: value,
|
||||
})
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
// Or a condition by or .or 一个条件
|
||||
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,>=,<=)
|
||||
value: value,
|
||||
})
|
||||
|
||||
// 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{
|
||||
andor: "or",
|
||||
column: column, // 列名
|
||||
case_: cases, // 条件(and,or,in,>=,<=)
|
||||
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{}) {
|
||||
|
||||
@@ -143,6 +143,7 @@ func TestCondition(t *testing.T) {
|
||||
condition := model.Condition{}
|
||||
condition.And(model.AccountColumns.AccountID, ">=", "1")
|
||||
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"})
|
||||
|
||||
where, obj := condition.Get()
|
||||
@@ -155,6 +156,6 @@ func TestCondition(t *testing.T) {
|
||||
sqldb.Close()
|
||||
}()
|
||||
|
||||
accountMgr := model.AccountMgr(db.Where(condition.Get()))
|
||||
accountMgr := model.AccountMgr(db.Where(where, obj...))
|
||||
accountMgr.Gets()
|
||||
}
|
||||
|
||||
@@ -97,24 +97,38 @@ type Condition struct {
|
||||
list []*conditionInfo
|
||||
}
|
||||
|
||||
// And a condition by and .and 一个条件
|
||||
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,>=,<=)
|
||||
value: value,
|
||||
})
|
||||
func (c *Condition) AndWithCondition(condition bool, column string, cases string, value interface{}) (*Condition) {
|
||||
if condition {
|
||||
c.list = append(c.list, &conditionInfo{
|
||||
andor: "and",
|
||||
column: column, // 列名
|
||||
case_: cases, // 条件(and,or,in,>=,<=)
|
||||
value: value,
|
||||
})
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
// Or a condition by or .or 一个条件
|
||||
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,>=,<=)
|
||||
value: value,
|
||||
})
|
||||
// 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{
|
||||
andor: "or",
|
||||
column: column, // 列名
|
||||
case_: cases, // 条件(and,or,in,>=,<=)
|
||||
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{}) {
|
||||
|
||||
Reference in New Issue
Block a user