opt: 修改AND操作符,适配Ors情况
This commit is contained in:
parent
bc6f4ae6c4
commit
20316abc31
@ -39,6 +39,7 @@ type Condition struct {
|
||||
Field string // 字段
|
||||
Operator string // 操作类型
|
||||
Arg interface{} // 值
|
||||
Args []interface{}
|
||||
}
|
||||
|
||||
// PaginationQuery 查询条件
|
||||
@ -123,8 +124,8 @@ func (q *PaginationQuery) Ors(condition string) {
|
||||
}
|
||||
|
||||
// And 自定义条件, 如: (length(field) = 4 OR length(field) = 6)
|
||||
func (q *PaginationQuery) And(condition string) {
|
||||
q.Conditions = append(q.Conditions, Condition{Field: condition, Operator: "and"})
|
||||
func (q *PaginationQuery) And(condition string, args ...interface{}) {
|
||||
q.Conditions = append(q.Conditions, Condition{Field: condition, Operator: "and", Args: args})
|
||||
}
|
||||
|
||||
// Group GROUP BY
|
||||
@ -244,7 +245,8 @@ func (q *PaginationQuery) BuildRawWhere() (where string, args []interface{}) {
|
||||
sb.WriteString(fmt.Sprintf(" OR %s = ?", con.Field))
|
||||
args = append(args, con.Arg)
|
||||
case "and":
|
||||
sb.WriteString(fmt.Sprintf(" AND %s", con.Field)) // 自定义条件, 如: (length(field) = 4 OR length(field) = 6)
|
||||
sb.WriteString(fmt.Sprintf(" AND (%s)", con.Field)) // 自定义条件, 如: (length(field) = 4 OR length(field) = 6)
|
||||
args = append(args, con.Args...)
|
||||
case "group":
|
||||
sb.WriteString(fmt.Sprintf(" GROUP BY %s", con.Field))
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user