Add implicit cross join support
This commit is contained in:
parent
0cba1f6401
commit
4ef0113f6b
6 changed files with 55 additions and 15 deletions
|
|
@ -44,7 +44,7 @@ type SelectStatement interface {
|
|||
Expression
|
||||
|
||||
DISTINCT() SelectStatement
|
||||
FROM(table ReadableTable) SelectStatement
|
||||
FROM(tables ...ReadableTable) SelectStatement
|
||||
WHERE(expression BoolExpression) SelectStatement
|
||||
GROUP_BY(groupByClauses ...jet.GroupByClause) SelectStatement
|
||||
HAVING(boolExpression BoolExpression) SelectStatement
|
||||
|
|
@ -76,7 +76,9 @@ func newSelectStatement(table ReadableTable, projections []Projection) SelectSta
|
|||
&newSelect.Limit, &newSelect.Offset, &newSelect.For)
|
||||
|
||||
newSelect.Select.ProjectionList = projections
|
||||
newSelect.From.Table = table
|
||||
if table != nil {
|
||||
newSelect.From.Tables = []jet.Serializer{table}
|
||||
}
|
||||
newSelect.Limit.Count = -1
|
||||
newSelect.Offset.Count = -1
|
||||
|
||||
|
|
@ -106,8 +108,10 @@ func (s *selectStatementImpl) DISTINCT() SelectStatement {
|
|||
return s
|
||||
}
|
||||
|
||||
func (s *selectStatementImpl) FROM(table ReadableTable) SelectStatement {
|
||||
s.From.Table = table
|
||||
func (s *selectStatementImpl) FROM(tables ...ReadableTable) SelectStatement {
|
||||
for _, table := range tables {
|
||||
s.From.Tables = append(s.From.Tables, table)
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -99,3 +99,26 @@ CROSS JOIN db.table2`)
|
|||
CROSS JOIN db.table2
|
||||
CROSS JOIN db.table3`)
|
||||
}
|
||||
|
||||
func TestImplicitCROSS_JOIN(t *testing.T) {
|
||||
assertDebugStatementSql(t,
|
||||
SELECT(table1Col1, table2Col3).
|
||||
FROM(table1, table2),
|
||||
`
|
||||
SELECT table1.col1 AS "table1.col1",
|
||||
table2.col3 AS "table2.col3"
|
||||
FROM db.table1,
|
||||
db.table2;
|
||||
`)
|
||||
assertDebugStatementSql(t,
|
||||
SELECT(
|
||||
table1Col1, table2Col3,
|
||||
).FROM(table1, table2, table3),
|
||||
`
|
||||
SELECT table1.col1 AS "table1.col1",
|
||||
table2.col3 AS "table2.col3"
|
||||
FROM db.table1,
|
||||
db.table2,
|
||||
db.table3;
|
||||
`)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue