-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsql_select_test.go
105 lines (97 loc) · 5.02 KB
/
sql_select_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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package StitchingSQLGo
import (
"github.com/google/go-cmp/cmp"
"testing"
)
//go:generate stitching_sql -type=TestSelect_SQLTable -file-name=sql_select_table_stitching_sql_test.go -is-add-import=false
type TestSelect_SQLTable struct {
Field1 int
Field2 int
Field3 int
}
func TestSelect_SQL(t *testing.T) {
s := Select{
FS: Fields{
Field1{},
TestSelect_SQLTable_F.Field1,
TestSelect_SQLTable_F.Field2,
TestSelect_SQLTable_F.Field3,
Field1{},
},
Table: TestSelect_SQLTable{},
Where: Where{
Condition{
L: TestSelect_SQLTable_F.Field1,
O: EQ,
R: 1,
},
AND,
WhereItems{
Condition{
L: TestSelect_SQLTable_F.Field1,
O: EQ,
R: 2,
},
AND,
Condition{
L: TestSelect_SQLTable_F.Field2,
O: NEQ,
R: 3,
},
AND,
Condition{
L: TestSelect_SQLTable_F.Field2,
O: GT,
R: 4,
},
AND,
WhereItems{
Condition{
L: TestSelect_SQLTable_F.Field1,
O: EQ,
R: 5,
},
AND,
Condition{
L: TestSelect_SQLTable_F.Field2,
O: NEQ,
R: 6,
},
AND,
Condition{
L: TestSelect_SQLTable_F.Field2,
O: GT,
R: 7,
},
},
},
},
OrderBy: map[Field]OrderByKind{
TestSelect_SQLTable_F.Field1: ASC,
TestSelect_SQLTable_F.Field2: DESC,
TestSelect_SQLTable_F.Field3: ASC,
},
Limit: 1,
Offset: 1,
For: ForUpdate,
}
sql, args, err := s.SQL()
if err != nil {
t.Fatal(err)
}
excepts := map[string][]interface{}{
"select 1, test_select__sqltable.field1, test_select__sqltable.field2, test_select__sqltable.field3, 1 from test_select__sqltable where test_select__sqltable.field1 = $1 and ( test_select__sqltable.field1 = $2 and test_select__sqltable.field2 != $3 and test_select__sqltable.field2 > $4 and ( test_select__sqltable.field1 = $5 and test_select__sqltable.field2 != $6 and test_select__sqltable.field2 > $7)) order by test_select__sqltable.field1 asc, test_select__sqltable.field2 desc, test_select__sqltable.field3 asc limit 1 offset 1 for update": {1, 2, 3, 4, 5, 6, 7},
"select 1, test_select__sqltable.field1, test_select__sqltable.field2, test_select__sqltable.field3, 1 from test_select__sqltable where test_select__sqltable.field1 = $1 and ( test_select__sqltable.field1 = $2 and test_select__sqltable.field2 != $3 and test_select__sqltable.field2 > $4 and ( test_select__sqltable.field1 = $5 and test_select__sqltable.field2 != $6 and test_select__sqltable.field2 > $7)) order by test_select__sqltable.field2 desc, test_select__sqltable.field1 asc, test_select__sqltable.field3 asc limit 1 offset 1 for update": {1, 2, 3, 4, 5, 6, 7},
"select 1, test_select__sqltable.field1, test_select__sqltable.field2, test_select__sqltable.field3, 1 from test_select__sqltable where test_select__sqltable.field1 = $1 and ( test_select__sqltable.field1 = $2 and test_select__sqltable.field2 != $3 and test_select__sqltable.field2 > $4 and ( test_select__sqltable.field1 = $5 and test_select__sqltable.field2 != $6 and test_select__sqltable.field2 > $7)) order by test_select__sqltable.field3 asc, test_select__sqltable.field2 desc, test_select__sqltable.field1 asc limit 1 offset 1 for update": {1, 2, 3, 4, 5, 6, 7},
"select 1, test_select__sqltable.field1, test_select__sqltable.field2, test_select__sqltable.field3, 1 from test_select__sqltable where test_select__sqltable.field1 = $1 and ( test_select__sqltable.field1 = $2 and test_select__sqltable.field2 != $3 and test_select__sqltable.field2 > $4 and ( test_select__sqltable.field1 = $5 and test_select__sqltable.field2 != $6 and test_select__sqltable.field2 > $7)) order by test_select__sqltable.field2 desc, test_select__sqltable.field3 asc, test_select__sqltable.field1 asc limit 1 offset 1 for update": {1, 2, 3, 4, 5, 6, 7},
"select 1, test_select__sqltable.field1, test_select__sqltable.field2, test_select__sqltable.field3, 1 from test_select__sqltable where test_select__sqltable.field1 = $1 and ( test_select__sqltable.field1 = $2 and test_select__sqltable.field2 != $3 and test_select__sqltable.field2 > $4 and ( test_select__sqltable.field1 = $5 and test_select__sqltable.field2 != $6 and test_select__sqltable.field2 > $7)) order by test_select__sqltable.field3 asc, test_select__sqltable.field1 asc, test_select__sqltable.field2 desc limit 1 offset 1 for update": {1, 2, 3, 4, 5, 6, 7},
"select 1, test_select__sqltable.field1, test_select__sqltable.field2, test_select__sqltable.field3, 1 from test_select__sqltable where test_select__sqltable.field1 = $1 and ( test_select__sqltable.field1 = $2 and test_select__sqltable.field2 != $3 and test_select__sqltable.field2 > $4 and ( test_select__sqltable.field1 = $5 and test_select__sqltable.field2 != $6 and test_select__sqltable.field2 > $7)) order by test_select__sqltable.field1 asc, test_select__sqltable.field3 asc, test_select__sqltable.field2 desc limit 1 offset 1 for update": {1, 2, 3, 4, 5, 6, 7},
}
exceptArgs, ok := excepts[sql]
if ok == false {
t.Fatalf("now\n%s", sql)
}
if cmp.Equal(exceptArgs, args) == false {
t.Fatalf("except\n%v\nnow\n%v", exceptArgs, args)
}
}