Add implicit cross join support
This commit is contained in:
parent
0cba1f6401
commit
4ef0113f6b
6 changed files with 55 additions and 15 deletions
|
|
@ -45,19 +45,25 @@ func (s *ClauseSelect) Serialize(statementType StatementType, out *SQLBuilder, o
|
|||
|
||||
// ClauseFrom struct
|
||||
type ClauseFrom struct {
|
||||
Table Serializer
|
||||
Tables []Serializer
|
||||
}
|
||||
|
||||
// Serialize serializes clause into SQLBuilder
|
||||
func (f *ClauseFrom) Serialize(statementType StatementType, out *SQLBuilder, options ...SerializeOption) {
|
||||
if f.Table == nil {
|
||||
if len(f.Tables) == 0 { // SELECT statement does not have to have FROM clause
|
||||
return
|
||||
}
|
||||
out.NewLine()
|
||||
out.WriteString("FROM")
|
||||
|
||||
out.IncreaseIdent()
|
||||
f.Table.serialize(statementType, out, FallTrough(options)...)
|
||||
for i, table := range f.Tables {
|
||||
if i > 0 {
|
||||
out.WriteString(",")
|
||||
out.NewLine()
|
||||
}
|
||||
table.serialize(statementType, out, FallTrough(options)...)
|
||||
}
|
||||
out.DecreaseIdent()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -136,9 +136,6 @@ func (t *joinTableImpl) TableName() string {
|
|||
return ""
|
||||
}
|
||||
|
||||
func (t *joinTableImpl) AS(alias string) {
|
||||
}
|
||||
|
||||
func (t *joinTableImpl) columns() []Column {
|
||||
var ret []Column
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import (
|
|||
"github.com/go-jet/jet/v2/internal/utils"
|
||||
"github.com/go-jet/jet/v2/qrm"
|
||||
"github.com/google/uuid"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
|
@ -116,7 +117,12 @@ func AssertDebugStatementSql(t *testing.T, query jet.Statement, expectedQuery st
|
|||
}
|
||||
|
||||
debuqSql := query.DebugSql()
|
||||
require.Equal(t, debuqSql, expectedQuery)
|
||||
if !assert.Equal(t, debuqSql, expectedQuery) {
|
||||
fmt.Println("Expected: ")
|
||||
fmt.Println(expectedQuery)
|
||||
fmt.Println("Got: ")
|
||||
fmt.Println(debuqSql)
|
||||
}
|
||||
}
|
||||
|
||||
// AssertSerialize checks if clause serialize produces expected query and args
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue