forked from mirror/gorm
feat: QuoteTo accept clause.Expr (#4621)
* feat: QuoteTo accept clause.Expr * test: update Expr build test
This commit is contained in:
parent
2b2f6e77af
commit
25f561a742
|
@ -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 {
|
||||||
|
|
|
@ -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:
|
||||||
|
|
Loading…
Reference in New Issue