From 20316abc31a72174d2ddb1f7db8b472b23c53ff3 Mon Sep 17 00:00:00 2001 From: wangjie Date: Sat, 2 Aug 2025 11:28:51 +0800 Subject: [PATCH] =?UTF-8?q?opt:=20=E4=BF=AE=E6=94=B9AND=E6=93=8D=E4=BD=9C?= =?UTF-8?q?=E7=AC=A6=EF=BC=8C=E9=80=82=E9=85=8DOrs=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lxDb/model.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lxDb/model.go b/lxDb/model.go index 34cdfa3..29bf369 100644 --- a/lxDb/model.go +++ b/lxDb/model.go @@ -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))