forked from slicebit/qb
-
Notifications
You must be signed in to change notification settings - Fork 2
/
delete_test.go
36 lines (27 loc) · 833 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
package qb
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestDelete(t *testing.T) {
dialect := NewDialect("default")
users := Table(
"users",
Column("id", Varchar().Size(36)),
Column("email", Varchar()).Unique(),
)
var statement *Stmt
statement = Delete(users).
Where(Eq(users.C("id"), 5)).
Build(dialect)
assert.Equal(t, "DELETE FROM users\nWHERE users.id = ?;", statement.SQL())
assert.Equal(t, []interface{}{5}, statement.Bindings())
statement = Delete(users).
Where(Eq(users.C("id"), 5)).
Returning(users.C("id")).
Build(dialect)
assert.Equal(t, "DELETE FROM users\nWHERE users.id = ?\nRETURNING id;", statement.SQL())
assert.Equal(t, []interface{}{5}, statement.Bindings())
statement = Delete(users).Build(dialect)
assert.Equal(t, "DELETE FROM users;", statement.SQL())
}