-
Notifications
You must be signed in to change notification settings - Fork 2
/
join_test.go
52 lines (42 loc) · 1.07 KB
/
join_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
package sol
import (
"testing"
"github.com/aodin/sol/types"
)
var tableA = Table("a",
Column("id", types.Integer()),
Column("value", types.Varchar()),
)
var tableB = Table("b",
Column("id", types.Integer()),
Column("value", types.Varchar()),
)
var relations = Table("relations",
Column("a_id", types.Integer()),
Column("b_id", types.Integer()),
Unique("a_id", "b_id"),
)
func TestJoinClause(t *testing.T) {
expect := NewTester(t, &defaultDialect{})
expect.SQL(
Select(tableA).CrossJoin(relations),
`SELECT a.id, a.value FROM a CROSS JOIN relations`,
)
expect.SQL(
Select(tableA).InnerJoin(relations),
`SELECT a.id, a.value FROM a NATURAL INNER JOIN relations`,
)
expect.SQL(
Select(tableA).LeftOuterJoin(
relations,
tableA.C("id").Equals(relations.C("a_id")),
tableA.C("id").Equals(2),
).LeftOuterJoin(
tableB,
tableB.C("id").Equals(relations.C("b_id")),
),
`SELECT a.id, a.value FROM a LEFT OUTER JOIN relations ON a.id = relations.a_id AND a.id = $1 LEFT OUTER JOIN b ON b.id = relations.b_id`,
2,
)
// TODO self join with alias
}