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

test: Add more analyzer test cases #2866

Merged
merged 2 commits into from
Oct 17, 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
1 change: 1 addition & 0 deletions internal/endtoend/testdata/column_alias/issue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/sqlc-dev/sqlc/issues/1739
3 changes: 3 additions & 0 deletions internal/endtoend/testdata/column_alias/stdlib/exec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"contexts": ["managed-db"]
}
31 changes: 31 additions & 0 deletions internal/endtoend/testdata/column_alias/stdlib/go/db.go

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

18 changes: 18 additions & 0 deletions internal/endtoend/testdata/column_alias/stdlib/go/models.go

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

80 changes: 80 additions & 0 deletions internal/endtoend/testdata/column_alias/stdlib/go/query.sql.go

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

21 changes: 21 additions & 0 deletions internal/endtoend/testdata/column_alias/stdlib/query.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
-- name: GetUsers :many
SELECT
users.id,
users.fname,
users.lname,
users.email,
users.created_at,
rank_email,
rank_fname,
rank_lname,
similarity
FROM
users,
to_tsvector(users.email || users.fname || users.lname) document,
to_tsquery(@search_term::TEXT) query,
NULLIF(ts_rank(to_tsvector(users.email), query), 0) rank_email,
NULLIF(ts_rank(to_tsvector(users.fname), query), 0) rank_fname,
NULLIF(ts_rank(to_tsvector(users.lname), query), 0) rank_lname,
SIMILARITY(@search_term::TEXT, users.email || users.fname || users.lname) similarity
WHERE query @@ document OR similarity > 0
ORDER BY rank_email, rank_lname, rank_fname, similarity DESC NULLS LAST;
12 changes: 12 additions & 0 deletions internal/endtoend/testdata/column_alias/stdlib/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
CREATE EXTENSION pg_trgm;
CREATE EXTENSION pgcrypto;

CREATE TABLE users(
id INT GENERATED ALWAYS AS IDENTITY NOT NULL,
fname VARCHAR(100) NOT NULL,
lname VARCHAR(100) NOT NULL,
email VARCHAR(100) NOT NULL UNIQUE,
enc_passwd TEXT NOT NULL,
created_at TIMESTAMP WITH TIME ZONE NOT NULL default (NOW() AT TIME ZONE 'utc'),
PRIMARY KEY(id)
);
10 changes: 10 additions & 0 deletions internal/endtoend/testdata/column_alias/stdlib/sqlc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: "2"
sql:
- engine: "postgresql"
schema: "schema.sql"
queries: "query.sql"
gen:
go:
package: "querytest"
out: "go"
sql_package: "database/sql"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/sqlc-dev/sqlc/pull/2639
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"contexts": ["managed-db"]
}

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

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- name: Subquery :many
SELECT
a,
name,
(SELECT alias FROM bar WHERE bar.a=foo.a AND alias = $1 ORDER BY bar.a DESC limit 1) as alias
FROM FOO WHERE a = $2;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CREATE TABLE foo (a int not null, name text);
CREATE TABLE bar (a int not null, alias text);
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: "2"
sql:
- engine: "postgresql"
schema: "schema.sql"
queries: "query.sql"
gen:
go:
package: "querytest"
out: "go"
sql_package: "database/sql"
Loading