Skip to content

Commit

Permalink
add custom join type where user can fill in the join expression
Browse files Browse the repository at this point in the history
  • Loading branch information
darwin67 committed Sep 9, 2024
1 parent acd0ef5 commit 8169c34
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
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
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.CustomJoinType: []byte(" "), // User need to fill in the join statement themselves
},

TimeFormat: time.RFC3339Nano,
Expand Down

0 comments on commit 8169c34

Please sign in to comment.