Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(compiler): Skip analysis of queries without a name annotation #3072

Merged
merged 2 commits into from
Dec 20, 2023
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
4 changes: 4 additions & 0 deletions internal/compiler/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ func (c *Compiler) parseQuery(stmt ast.Node, src string, o opts.Parser) (*Query,
return nil, err
}

if name == "" {
return nil, nil
}

if err := validate.Cmd(raw.Stmt, name, cmd); err != nil {
return nil, err
}
Expand Down
3 changes: 3 additions & 0 deletions internal/endtoend/testdata/builtins/postgresql/exec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"contexts": ["base"]
}
274 changes: 274 additions & 0 deletions internal/endtoend/testdata/builtins/postgresql/go/query.sql.go

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

25 changes: 24 additions & 1 deletion internal/endtoend/testdata/builtins/postgresql/query.sql
Original file line number Diff line number Diff line change
@@ -1,25 +1,48 @@
-- name: Abs :one
SELECT abs(-17.4);
-- name: Cbrt :one
SELECT cbrt(27.0);
-- name: Ceil :one
SELECT ceil(-42.8);
-- name: Ceiling :one
SELECT ceiling(-95.3);
-- name: Degrees :one
SELECT degrees(0.5);
-- name: Div :one
SELECT div(9,4);
-- name: Exp :one
SELECT exp(1.0);
-- name: Floor :one
SELECT floor(-42.8);
-- name: Ln :one
SELECT ln(2.0);
-- name: Log :one
SELECT log(100.0);
-- name: Logs :one
SELECT log(2.0, 64.0);
-- name: Mod :one
SELECT mod(9,4);
-- name: Pi :one
SELECT pi();
-- name: Power :one
SELECT power(9.0, 3.0);
-- name: Radians :one
SELECT radians(45.0);
-- name: Round :one
SELECT round(42.4);
-- name: Rounds :one
SELECT round(42.4382, 2);
-- name: Scale :one
SELECT scale(8.41);
-- name: Sign :one
SELECT sign(-8.4);
-- name: Sqrt :one
SELECT sqrt(2.0);
-- name: Trunc :one
SELECT trunc(42.8);
-- name: Truncs :one
SELECT trunc(42.4382, 2);
-- name: WidthBucketNumerics :one
SELECT width_bucket(5.35, 0.024, 10.06, 5);
-- name: WidthBucketTimestamps :one
SELECT width_bucket(now(), array['yesterday', 'today', 'tomorrow']::timestamptz[]);
create schema if not exists sqlc;
21 changes: 21 additions & 0 deletions internal/endtoend/testdata/datatype/mysql/go/query.sql.go

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

1 change: 1 addition & 0 deletions internal/endtoend/testdata/datatype/mysql/sql/query.sql
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
-- name: Test :one
SELECT 1;
21 changes: 21 additions & 0 deletions internal/endtoend/testdata/datatype/pgx/v4/go/query.sql.go

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

1 change: 1 addition & 0 deletions internal/endtoend/testdata/datatype/pgx/v4/sql/query.sql
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
-- name: Test :one
SELECT 1;
Loading
Loading