Add LATERAL query support
This commit is contained in:
parent
4ef0113f6b
commit
0f773b26d6
6 changed files with 224 additions and 12 deletions
|
|
@ -2,9 +2,19 @@ package postgres
|
|||
|
||||
import "github.com/go-jet/jet/v2/internal/jet"
|
||||
|
||||
func LATERAL(selectStmt SelectStatement, alias string) SelectTable {
|
||||
func LATERAL(selectStmt SelectStatement) lateralImpl {
|
||||
return lateralImpl{
|
||||
selectStmt: selectStmt,
|
||||
}
|
||||
}
|
||||
|
||||
type lateralImpl struct {
|
||||
selectStmt SelectStatement
|
||||
}
|
||||
|
||||
func (l lateralImpl) AS(alias string) SelectTable {
|
||||
subQuery := &selectTableImpl{
|
||||
SelectTable: jet.NewLateral(selectStmt, alias),
|
||||
SelectTable: jet.NewLateral(l.selectStmt, alias),
|
||||
}
|
||||
|
||||
subQuery.readableTableInterfaceImpl.parent = subQuery
|
||||
|
|
|
|||
|
|
@ -3,7 +3,12 @@ package postgres
|
|||
import "testing"
|
||||
|
||||
func TestLATERAL(t *testing.T) {
|
||||
assertSerialize(t, LATERAL(SELECT(Int(1)), "lat1"), `LATERAL (
|
||||
assertSerialize(t,
|
||||
LATERAL(
|
||||
SELECT(Int(1)),
|
||||
).AS("lat1"),
|
||||
|
||||
`LATERAL (
|
||||
SELECT $1
|
||||
) AS lat1`)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue