Skip to content
Merged
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
31 changes: 31 additions & 0 deletions internal/endtoend/testdata/select_cte/sqlite/go/db.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions internal/endtoend/testdata/select_cte/sqlite/go/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions internal/endtoend/testdata/select_cte/sqlite/go/query.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions internal/endtoend/testdata/select_cte/sqlite/query.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

-- name: ListAuthors :many
WITH abc AS (
SELECT 1 AS n
)
SELECT * FROM abc;
12 changes: 12 additions & 0 deletions internal/endtoend/testdata/select_cte/sqlite/sqlc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": "1",
"packages": [
{
"path": "go",
"engine": "sqlite",
"schema": "query.sql",
"queries": "query.sql",
"name": "querytest"
}
]
}
22 changes: 22 additions & 0 deletions internal/engine/sqlite/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,25 @@ func (c *cc) convertMultiSelect_stmtContext(n *parser.Select_stmtContext) ast.No
var where ast.Node
var groups = []ast.Node{}
var having ast.Node
var ctes []ast.Node

if ct := n.Common_table_stmt(); ct != nil {
recursive := ct.RECURSIVE_() != nil
for _, cte := range ct.AllCommon_table_expression() {
tableName := identifier(cte.Table_name().GetText())
var cteCols ast.List
for _, col := range cte.AllColumn_name() {
cteCols.Items = append(cteCols.Items, NewIdentifer(col.GetText()))
}
ctes = append(ctes, &ast.CommonTableExpr{
Ctename: &tableName,
Ctequery: c.convert(cte.Select_stmt()),
Location: cte.GetStart().GetStart(),
Cterecursive: recursive,
Ctecolnames: &cteCols,
})
}
}

for _, icore := range n.AllSelect_core() {
core, ok := icore.(*parser.Select_coreContext)
Expand Down Expand Up @@ -377,6 +396,9 @@ func (c *cc) convertMultiSelect_stmtContext(n *parser.Select_stmtContext) ast.No
LimitCount: limitCount,
LimitOffset: limitOffset,
ValuesLists: &ast.List{},
WithClause: &ast.WithClause{
Ctes: &ast.List{Items: ctes},
},
}
}

Expand Down