Skip to content

Commit

Permalink
test: Add more analyzer test cases (#2866)
Browse files Browse the repository at this point in the history
* test: Add a test case for #1739

* test: Add a test case for #2639
  • Loading branch information
andrewmbenton authored Oct 17, 2023
1 parent 795bbc7 commit cbd90ec
Show file tree
Hide file tree
Showing 16 changed files with 301 additions and 0 deletions.
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"

0 comments on commit cbd90ec

Please sign in to comment.