Skip to content

Commit

Permalink
feat(compiler): Support DO statements (#2777)
Browse files Browse the repository at this point in the history
* feat(compiler): Support DO statements

* fix exec
  • Loading branch information
kyleconroy authored Sep 26, 2023
1 parent 0cfaf70 commit fd7168e
Show file tree
Hide file tree
Showing 14 changed files with 193 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/compiler/output_columns.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ func (c *Compiler) outputColumns(qc *QueryCatalog, node ast.Node) ([]*Column, er
if isUnion {
return c.outputColumns(qc, n.Larg)
}
case *ast.DoStmt:
targets = &ast.List{}
case *ast.CallStmt:
targets = &ast.List{}
case *ast.TruncateStmt, *ast.RefreshMatViewStmt, *ast.NotifyStmt, *ast.ListenStmt:
Expand Down Expand Up @@ -509,6 +511,8 @@ func (c *Compiler) sourceTables(qc *QueryCatalog, node ast.Node) ([]*Table, erro
list = &ast.List{
Items: append(n.FromClause.Items, n.Relations.Items...),
}
case *ast.DoStmt:
list = &ast.List{}
case *ast.CallStmt:
list = &ast.List{}
case *ast.NotifyStmt, *ast.ListenStmt:
Expand Down
1 change: 1 addition & 0 deletions internal/compiler/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func (c *Compiler) parseQuery(stmt ast.Node, src string, o opts.Parser) (*Query,
case *ast.CallStmt:
case *ast.SelectStmt:
case *ast.DeleteStmt:
case *ast.DoStmt:
case *ast.InsertStmt:
if err := validate.InsertStmt(n); err != nil {
return nil, err
Expand Down
32 changes: 32 additions & 0 deletions internal/endtoend/testdata/do/postgresql/pgx/db/db.go

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

15 changes: 15 additions & 0 deletions internal/endtoend/testdata/do/postgresql/pgx/db/models.go

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

24 changes: 24 additions & 0 deletions internal/endtoend/testdata/do/postgresql/pgx/db/query.sql.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/do/postgresql/pgx/query.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- name: DoStuff :exec
DO $$
BEGIN
ALTER TABLE authors
ADD COLUMN marked_for_processing bool;
END
$$;
5 changes: 5 additions & 0 deletions internal/endtoend/testdata/do/postgresql/pgx/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CREATE TABLE authors (
id BIGSERIAL PRIMARY KEY,
name text NOT NULL,
bio text
);
12 changes: 12 additions & 0 deletions internal/endtoend/testdata/do/postgresql/pgx/sqlc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": "1",
"packages": [
{
"path": "db",
"engine": "postgresql",
"schema": "schema.sql",
"queries": "query.sql",
"sql_package": "pgx/v5"
}
]
}
31 changes: 31 additions & 0 deletions internal/endtoend/testdata/do/postgresql/pq/db/db.go

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

15 changes: 15 additions & 0 deletions internal/endtoend/testdata/do/postgresql/pq/db/models.go

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

24 changes: 24 additions & 0 deletions internal/endtoend/testdata/do/postgresql/pq/db/query.sql.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/do/postgresql/pq/query.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- name: DoStuff :exec
DO $$
BEGIN
ALTER TABLE authors
ADD COLUMN marked_for_processing bool;
END
$$;
5 changes: 5 additions & 0 deletions internal/endtoend/testdata/do/postgresql/pq/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CREATE TABLE authors (
id BIGSERIAL PRIMARY KEY,
name text NOT NULL,
bio text
);
11 changes: 11 additions & 0 deletions internal/endtoend/testdata/do/postgresql/pq/sqlc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"version": "1",
"packages": [
{
"path": "db",
"engine": "postgresql",
"schema": "schema.sql",
"queries": "query.sql"
}
]
}

0 comments on commit fd7168e

Please sign in to comment.