forked from umisama/go-sqlbuilder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete_test.go
More file actions
49 lines (45 loc) · 1.05 KB
/
delete_test.go
File metadata and controls
49 lines (45 loc) · 1.05 KB
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
40
41
42
43
44
45
46
47
48
49
package sqlbuilder
import (
"testing"
)
func TestDelete(t *testing.T) {
table1 := NewTable(
"TABLE_A",
&TableOption{},
IntColumn("id", &ColumnOption{
PrimaryKey: true,
}),
IntColumn("test1", nil),
IntColumn("test2", nil),
)
table2 := NewTable(
"TABLE_B",
&TableOption{},
IntColumn("id", &ColumnOption{
PrimaryKey: true,
}),
)
tableJoined := table1.InnerJoin(table2, table1.C("test1").Eq(table2.C("id")))
var cases = []statementTestCase{{
stmt: Delete(table1).Where(table1.C("id").Eq(1)),
query: `DELETE FROM "TABLE_A" WHERE "TABLE_A"."id"=?;`,
args: []interface{}{int64(1)},
errmsg: "",
}, {
stmt: Delete(nil).Where(table1.C("id").Eq(1)),
query: ``,
args: []interface{}{},
errmsg: "sqlbuilder: from is nil.",
}, {
stmt: Delete(tableJoined).Where(table1.C("id").Eq(1)),
query: ``,
args: []interface{}{},
errmsg: "sqlbuilder: CreateTable can use only natural table.",
}}
for num, c := range cases {
mes, args, ok := c.Run()
if !ok {
t.Errorf(mes+" (case no.%d)", append(args, num)...)
}
}
}