Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Array Join support #364

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions exp/exp.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,7 @@ const (
NaturalRightJoinType
NaturalFullJoinType
CrossJoinType
ArrayJoinType

UsingJoinCondType JoinConditionType = iota
OnJoinCondType
Expand Down Expand Up @@ -729,6 +730,8 @@ func (jt JoinType) String() string {
return "NaturalFullJoinType"
case CrossJoinType:
return "CrossJoinType"
case ArrayJoinType:
return "ArrayJoinType"
}
return fmt.Sprintf("%d", jt)
}
5 changes: 5 additions & 0 deletions select_dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,11 @@ func (sd *SelectDataset) CrossJoin(table exp.Expression) *SelectDataset {
return sd.joinTable(exp.NewUnConditionedJoinExpression(exp.CrossJoinType, table))
}

// Adds a CROSS JOIN clause. See examples.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a a CROSS JOIN.

func (sd *SelectDataset) ArrayJoin(expression exp.Expression) *SelectDataset {
return sd.joinTable(exp.NewUnConditionedJoinExpression(exp.ArrayJoinType, expression))
}

// Joins this Datasets table with another
func (sd *SelectDataset) joinTable(join exp.JoinExpression) *SelectDataset {
return sd.copy(sd.clauses.JoinsAppend(join))
Expand Down
18 changes: 18 additions & 0 deletions select_dataset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,24 @@ func (sds *selectDatasetSuite) TestCrossJoin() {
)
}

func (sds *selectDatasetSuite) TestArrayJoin() {
bd := goqu.From("test")
sds.assertCases(
selectTestCase{
ds: bd.ArrayJoin(goqu.T("foo")),
clauses: exp.NewSelectClauses().
SetFrom(exp.NewColumnListExpression("test")).
JoinsAppend(
exp.NewUnConditionedJoinExpression(exp.ArrayJoinType, goqu.T("foo")),
),
},
selectTestCase{
ds: bd,
clauses: exp.NewSelectClauses().SetFrom(exp.NewColumnListExpression("test")),
},
)
}

func (sds *selectDatasetSuite) TestWhere() {
w := goqu.Ex{"a": 1}
w2 := goqu.Ex{"b": "c"}
Expand Down
1 change: 1 addition & 0 deletions sqlgen/sql_dialect_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,7 @@ func DefaultDialectOptions() *SQLDialectOptions {
exp.NaturalRightJoinType: []byte(" NATURAL RIGHT JOIN "),
exp.NaturalFullJoinType: []byte(" NATURAL FULL JOIN "),
exp.CrossJoinType: []byte(" CROSS JOIN "),
exp.ArrayJoinType: []byte(" ARRAY JOIN "),
},

TimeFormat: time.RFC3339Nano,
Expand Down