Skip to content

Commit 32d72a1

Browse files
committed
update tests
1 parent 95f448a commit 32d72a1

3 files changed

+32
-2
lines changed

select_dataset_example_test.go

+12-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515

1616
const schema = `
1717
DROP TABLE IF EXISTS "user_role";
18-
DROP TABLE IF EXISTS "goqu_user";
18+
DROP TABLE IF EXISTS "goqu_user";
1919
CREATE TABLE "goqu_user" (
2020
"id" SERIAL PRIMARY KEY NOT NULL,
2121
"first_name" VARCHAR(45) NOT NULL,
@@ -27,7 +27,7 @@ const schema = `
2727
"user_id" BIGINT NOT NULL REFERENCES goqu_user(id) ON DELETE CASCADE,
2828
"name" VARCHAR(45) NOT NULL,
2929
"created" TIMESTAMP NOT NULL DEFAULT now()
30-
);
30+
);
3131
`
3232

3333
const defaultDBURI = "postgres://postgres:@localhost:5435/goqupostgres?sslmode=disable"
@@ -968,6 +968,16 @@ func ExampleSelectDataset_CrossJoin() {
968968
// SELECT * FROM "test" CROSS JOIN (SELECT * FROM "test2" WHERE ("amount" > 0)) AS "t"
969969
}
970970

971+
func ExampleSelectDataset_CustomJoin() {
972+
join := goqu.L("ARRAY JOIN tags").As("tag")
973+
974+
sql, _, _ := goqu.From("test").CustomJoin(join).ToSQL()
975+
fmt.Println(sql)
976+
977+
// Output:
978+
// SELECT * FROM "test" ARRAY JOIN tags AS tag
979+
}
980+
971981
func ExampleSelectDataset_FromSelf() {
972982
sql, _, _ := goqu.From("test").FromSelf().ToSQL()
973983
fmt.Println(sql)

select_dataset_test.go

+14
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,20 @@ func (sds *selectDatasetSuite) TestCrossJoin() {
625625
)
626626
}
627627

628+
func (sds *selectDatasetSuite) TestCustomJoin() {
629+
bd := goqu.From("test")
630+
sds.assertCases(
631+
selectTestCase{
632+
ds: bd.CustomJoin(goqu.L("ARRAY JOIN tags").As("tag")),
633+
clauses: exp.NewSelectClauses().
634+
SetFrom(exp.NewColumnListExpression("test")).
635+
JoinsAppend(
636+
exp.NewUnConditionedJoinExpression(exp.CustomJoinType, goqu.L("ARRAY JOIN tags").As("tag")),
637+
),
638+
},
639+
)
640+
}
641+
628642
func (sds *selectDatasetSuite) TestWhere() {
629643
w := goqu.Ex{"a": 1}
630644
w2 := goqu.Ex{"b": "c"}

sqlgen/select_sql_generator_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ func (ssgs *selectSQLGeneratorSuite) TestGenerate_withJoin() {
216216
opts.JoinTypeLookup = map[exp.JoinType][]byte{
217217
exp.LeftJoinType: []byte(" left join "),
218218
exp.NaturalJoinType: []byte(" natural join "),
219+
exp.CustomJoinType: []byte(" "),
219220
}
220221

221222
sc := exp.NewSelectClauses().SetFrom(exp.NewColumnListExpression("test"))
@@ -224,6 +225,7 @@ func (ssgs *selectSQLGeneratorSuite) TestGenerate_withJoin() {
224225
cjo := exp.NewConditionedJoinExpression(exp.LeftJoinType, ti, exp.NewJoinOnCondition(exp.Ex{"a": "foo"}))
225226
cju := exp.NewConditionedJoinExpression(exp.LeftJoinType, ti, exp.NewJoinUsingCondition("a"))
226227
rj := exp.NewConditionedJoinExpression(exp.RightJoinType, ti, exp.NewJoinUsingCondition(exp.NewIdentifierExpression("", "", "a")))
228+
cj := exp.NewUnConditionedJoinExpression(exp.CustomJoinType, goqu.L("ARRAY JOIN tags").As("tag"))
227229
badJoin := exp.NewConditionedJoinExpression(exp.LeftJoinType, ti, exp.NewJoinUsingCondition())
228230

229231
expectedRjError := "goqu: dialect does not support RightJoinType"
@@ -254,6 +256,10 @@ func (ssgs *selectSQLGeneratorSuite) TestGenerate_withJoin() {
254256
isPrepared: true,
255257
args: []interface{}{"foo"},
256258
},
259+
selectTestCase{
260+
clause: sc.JoinsAppend(cj),
261+
sql: `SELECT * FROM "test" ARRAY JOIN tags AS "tag"`,
262+
},
257263

258264
selectTestCase{clause: sc.JoinsAppend(rj), err: expectedRjError},
259265
selectTestCase{clause: sc.JoinsAppend(rj), err: expectedRjError, isPrepared: true},

0 commit comments

Comments
 (0)