mirror of https://github.com/go-gorm/gorm.git
Support use clause.Interface as query params
This commit is contained in:
parent
62593cfad0
commit
3f20a543fa
|
@ -179,6 +179,10 @@ func (stmt *Statement) AddVar(writer clause.Writer, vars ...interface{}) {
|
|||
} else {
|
||||
stmt.AddVar(writer, v.GormValue(stmt.Context, stmt.DB))
|
||||
}
|
||||
case clause.Interface:
|
||||
c := clause.Clause{Name: v.Name()}
|
||||
v.MergeClause(&c)
|
||||
c.Build(stmt)
|
||||
case clause.Expression:
|
||||
v.Build(stmt)
|
||||
case driver.Valuer:
|
||||
|
|
|
@ -445,6 +445,14 @@ func TestToSQL(t *testing.T) {
|
|||
if DB.Statement.DryRun || DB.DryRun {
|
||||
t.Fatal("Failed expect DB.DryRun and DB.Statement.ToSQL to be false")
|
||||
}
|
||||
|
||||
// UpdateColumns
|
||||
sql = DB.ToSQL(func(tx *gorm.DB) *gorm.DB {
|
||||
return tx.Raw("SELECT * FROM users ?", clause.OrderBy{
|
||||
Columns: []clause.OrderByColumn{{Column: clause.Column{Name: "id", Raw: true}, Desc: true}},
|
||||
})
|
||||
})
|
||||
assertEqualSQL(t, `SELECT * FROM users ORDER BY id DESC`, sql)
|
||||
}
|
||||
|
||||
// assertEqualSQL for assert that the sql is equal, this method will ignore quote, and dialect specials.
|
||||
|
|
Loading…
Reference in New Issue