forked from ido50/sqlz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete_test.go
39 lines (34 loc) · 998 Bytes
/
delete_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package sqlz
import (
"testing"
)
func TestDelete(t *testing.T) {
runTests(t, func(dbz *DB) []test {
return []test{
{
"delete all table",
dbz.DeleteFrom("table"),
"DELETE FROM table",
[]interface{}{},
},
{
"delete all rows matching condition",
dbz.DeleteFrom("table").Where(Or(Eq("id", 1), And(Eq("name", "some-name"), Gt("integer", 3)))),
"DELETE FROM table WHERE id = ? OR (name = ? AND integer > ?)",
[]interface{}{1, "some-name", 3},
},
{
"delete with returning clause",
dbz.DeleteFrom("table").Where(Eq("id", 2)).Returning("name"),
"DELETE FROM table WHERE id = ? RETURNING name",
[]interface{}{2},
},
{
"delete using join",
dbz.DeleteFrom("table").Using("other", "another").Where(Eq("other.fk_id", Indirect("table.id")), Eq("another.fk_id", Indirect("table.id"))),
"DELETE FROM table USING other, another WHERE other.fk_id = table.id AND another.fk_id = table.id",
[]interface{}{},
},
}
})
}