Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
darwin67 committed Sep 9, 2024
1 parent 95f448a commit 32d72a1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
14 changes: 12 additions & 2 deletions select_dataset_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

const schema = `
DROP TABLE IF EXISTS "user_role";
DROP TABLE IF EXISTS "goqu_user";
DROP TABLE IF EXISTS "goqu_user";
CREATE TABLE "goqu_user" (
"id" SERIAL PRIMARY KEY NOT NULL,
"first_name" VARCHAR(45) NOT NULL,
Expand All @@ -27,7 +27,7 @@ const schema = `
"user_id" BIGINT NOT NULL REFERENCES goqu_user(id) ON DELETE CASCADE,
"name" VARCHAR(45) NOT NULL,
"created" TIMESTAMP NOT NULL DEFAULT now()
);
);
`

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

func ExampleSelectDataset_CustomJoin() {
join := goqu.L("ARRAY JOIN tags").As("tag")

sql, _, _ := goqu.From("test").CustomJoin(join).ToSQL()
fmt.Println(sql)

// Output:
// SELECT * FROM "test" ARRAY JOIN tags AS tag
}

func ExampleSelectDataset_FromSelf() {
sql, _, _ := goqu.From("test").FromSelf().ToSQL()
fmt.Println(sql)
Expand Down
14 changes: 14 additions & 0 deletions select_dataset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,20 @@ func (sds *selectDatasetSuite) TestCrossJoin() {
)
}

func (sds *selectDatasetSuite) TestCustomJoin() {
bd := goqu.From("test")
sds.assertCases(
selectTestCase{
ds: bd.CustomJoin(goqu.L("ARRAY JOIN tags").As("tag")),
clauses: exp.NewSelectClauses().
SetFrom(exp.NewColumnListExpression("test")).
JoinsAppend(
exp.NewUnConditionedJoinExpression(exp.CustomJoinType, goqu.L("ARRAY JOIN tags").As("tag")),
),
},
)
}

func (sds *selectDatasetSuite) TestWhere() {
w := goqu.Ex{"a": 1}
w2 := goqu.Ex{"b": "c"}
Expand Down
6 changes: 6 additions & 0 deletions sqlgen/select_sql_generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ func (ssgs *selectSQLGeneratorSuite) TestGenerate_withJoin() {
opts.JoinTypeLookup = map[exp.JoinType][]byte{
exp.LeftJoinType: []byte(" left join "),
exp.NaturalJoinType: []byte(" natural join "),
exp.CustomJoinType: []byte(" "),
}

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

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

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

0 comments on commit 32d72a1

Please sign in to comment.