Skip to content

Commit

Permalink
fix(compiler): Pull in array information from analyzer (#2864)
Browse files Browse the repository at this point in the history
* fix(compiler): Pull in array information from analyzer
Fixes #1532
* test(analyzer): Add testcase for #1574
* test: Added test for #1634
* test: Add test case for #1646
* test: Add test for #1714
* Fixes #1912
* test: Add case for #1916
* test: Add two test cases
#1917
#1545
* test: Add case for #1979
* test: Add case for #1990
  • Loading branch information
kyleconroy committed Oct 18, 2023
1 parent 02c9e3d commit 9ed0aca
Show file tree
Hide file tree
Showing 86 changed files with 1,142 additions and 2 deletions.
4 changes: 4 additions & 0 deletions internal/compiler/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ func combineAnalysis(prev *analysis, a *analyzer.Analysis) *analysis {
if len(prev.Columns) == len(cols) {
for i := range prev.Columns {
prev.Columns[i].DataType = cols[i].DataType
prev.Columns[i].IsArray = cols[i].IsArray
prev.Columns[i].ArrayDims = cols[i].ArrayDims
}
} else {
embedding := false
Expand All @@ -73,6 +75,8 @@ func combineAnalysis(prev *analysis, a *analyzer.Analysis) *analysis {
if len(prev.Parameters) == len(params) {
for i := range prev.Parameters {
prev.Parameters[i].Column.DataType = params[i].Column.DataType
prev.Parameters[i].Column.IsArray = params[i].Column.IsArray
prev.Parameters[i].Column.ArrayDims = params[i].Column.ArrayDims
}
} else {
prev.Parameters = params
Expand Down
3 changes: 2 additions & 1 deletion internal/endtoend/testdata/cte_recursive_employees/issue.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
https://github.com/sqlc-dev/sqlc/issues/1219
https://github.com/sqlc-dev/sqlc/issues/1219
https://github.com/sqlc-dev/sqlc/issues/1912

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/cte_update_multiple/issue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/sqlc-dev/sqlc/issues/1916
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,28 @@
-- name: UpdateUserAddressWithAddress :one
WITH t1 AS (
UPDATE "address" as a
SET
address_line = COALESCE(sqlc.narg(address_line),address_line),
region = COALESCE(sqlc.narg(region),region),
city= COALESCE(sqlc.narg(city),city)
WHERE id = COALESCE(sqlc.arg(id),id)
RETURNING a.id, a.address_line, a.region, a.city
),

t2 AS (
UPDATE "user_address"
SET
default_address = COALESCE(sqlc.narg(default_address),default_address)
WHERE
user_id = COALESCE(sqlc.arg(user_id),user_id)
AND address_id = COALESCE(sqlc.arg(address_id),address_id)
RETURNING user_id, address_id, default_address
)

SELECT
user_id,
address_id,
default_address,
address_line,
region,
city From t1,t2;
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
CREATE TABLE "user" (
"id" bigserial PRIMARY KEY NOT NULL,
"username" varchar NOT NULL,
"email" varchar UNIQUE NOT NULL,
"password" varchar NOT NULL,
"telephone" int NOT NULL DEFAULT 0,
"default_payment" bigint,
"created_at" timestamptz NOT NULL DEFAULT (now()),
"updated_at" timestamptz NOT NULL DEFAULT '0001-01-01 00:00:00Z'
);

CREATE TABLE "address" (
"id" bigserial PRIMARY KEY NOT NULL,
"address_line" varchar NOT NULL,
"region" varchar NOT NULL,
"city" varchar NOT NULL,
"created_at" timestamptz NOT NULL DEFAULT (now()),
"updated_at" timestamptz NOT NULL DEFAULT '0001-01-01 00:00:00Z'
);

CREATE TABLE "user_address" (
"user_id" bigint NOT NULL,
"address_id" bigint UNIQUE NOT NULL,
"default_address" bigint,
"created_at" timestamptz NOT NULL DEFAULT (now()),
"updated_at" timestamptz NOT NULL DEFAULT '0001-01-01 00:00:00Z'
);
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: "pgx/v5"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/sqlc-dev/sqlc/issues/1917
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"contexts": ["managed-db"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- name: SelectOne :one
SELECT 1;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CREATE TABLE test_table (
id STRING
);
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: "pgx/v5"
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# package querytest
query.sql:1:1: rpc error: code = FailedPrecondition desc = type "string" does not exist (42704)
CREATE TABLE test_table (
id STRING
);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/sqlc-dev/sqlc/issues/1545
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"contexts": ["managed-db"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- name: GetTotalEarned :one
SELECT COALESCE(SUM(earned), 0) as total_earned
FROM grouped_kpis
WHERE day = @day;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CREATE TABLE kpis (
ts TIMESTAMPTZ,
event_id TEXT NOT NULL
);

CREATE MATERIALIZED VIEW IF NOT EXISTS grouped_kpis AS
SELECT date_trunc('1 day', ts) as day, COUNT(*)
FROM kpis
GROUP BY 1;
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: "pgx/v5"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# package querytest
query.sql:2:21: column "earned" does not exist
1 change: 1 addition & 0 deletions internal/endtoend/testdata/delete_using/issue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/sqlc-dev/sqlc/issues/1714
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"contexts": ["managed-db"]
}
32 changes: 32 additions & 0 deletions internal/endtoend/testdata/delete_using/postgresql/pgx/go/db.go

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.

0 comments on commit 9ed0aca

Please sign in to comment.