feat: QuoteTo accept clause.Expr (#4621)

* feat: QuoteTo accept clause.Expr

* test: update Expr build test
This commit is contained in:
River 2021-08-19 14:33:18 +08:00 committed by GitHub
parent 2b2f6e77af
commit 25f561a742
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View File

@ -156,6 +156,18 @@ func TestExpression(t *testing.T) {
}, },
ExpectedVars: []interface{}{"a", "b"}, ExpectedVars: []interface{}{"a", "b"},
Result: "`column-name` NOT IN (?,?)", Result: "`column-name` NOT IN (?,?)",
}, {
Expressions: []clause.Expression{
clause.Eq{Column: clause.Expr{SQL: "SUM(?)", Vars: []interface{}{clause.Column{Name: "id"}}}, Value: 100},
},
ExpectedVars: []interface{}{100},
Result: "SUM(`id`) = ?",
}, {
Expressions: []clause.Expression{
clause.Gte{Column: clause.Expr{SQL: "SUM(?)", Vars: []interface{}{clause.Column{Table: "users", Name: "id"}}}, Value: 100},
},
ExpectedVars: []interface{}{100},
Result: "SUM(`users`.`id`) >= ?",
}} }}
for idx, result := range results { for idx, result := range results {

View File

@ -129,6 +129,8 @@ func (stmt *Statement) QuoteTo(writer clause.Writer, field interface{}) {
stmt.QuoteTo(writer, d) stmt.QuoteTo(writer, d)
} }
writer.WriteByte(')') writer.WriteByte(')')
case clause.Expr:
v.Build(stmt)
case string: case string:
stmt.DB.Dialector.QuoteTo(writer, v) stmt.DB.Dialector.QuoteTo(writer, v)
case []string: case []string: