Skip to content

Commit 9ed0aca

Browse files
authored
fix(compiler): Pull in array information from analyzer (#2864)
* 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
1 parent 02c9e3d commit 9ed0aca

File tree

86 files changed

+1142
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+1142
-2
lines changed

internal/compiler/analyze.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ func combineAnalysis(prev *analysis, a *analyzer.Analysis) *analysis {
5858
if len(prev.Columns) == len(cols) {
5959
for i := range prev.Columns {
6060
prev.Columns[i].DataType = cols[i].DataType
61+
prev.Columns[i].IsArray = cols[i].IsArray
62+
prev.Columns[i].ArrayDims = cols[i].ArrayDims
6163
}
6264
} else {
6365
embedding := false
@@ -73,6 +75,8 @@ func combineAnalysis(prev *analysis, a *analyzer.Analysis) *analysis {
7375
if len(prev.Parameters) == len(params) {
7476
for i := range prev.Parameters {
7577
prev.Parameters[i].Column.DataType = params[i].Column.DataType
78+
prev.Parameters[i].Column.IsArray = params[i].Column.IsArray
79+
prev.Parameters[i].Column.ArrayDims = params[i].Column.ArrayDims
7680
}
7781
} else {
7882
prev.Parameters = params
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
https://github.com/sqlc-dev/sqlc/issues/1219
1+
https://github.com/sqlc-dev/sqlc/issues/1219
2+
https://github.com/sqlc-dev/sqlc/issues/1912

internal/endtoend/testdata/cte_recursive_star/postgresql/pgx/go/query.sql.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://github.com/sqlc-dev/sqlc/issues/1916
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"contexts": ["managed-db"]
3+
}

internal/endtoend/testdata/cte_update_multiple/postgresql/pgx/go/db.go

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/cte_update_multiple/postgresql/pgx/go/models.go

Lines changed: 37 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/cte_update_multiple/postgresql/pgx/go/query.sql.go

Lines changed: 83 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
-- name: UpdateUserAddressWithAddress :one
2+
WITH t1 AS (
3+
UPDATE "address" as a
4+
SET
5+
address_line = COALESCE(sqlc.narg(address_line),address_line),
6+
region = COALESCE(sqlc.narg(region),region),
7+
city= COALESCE(sqlc.narg(city),city)
8+
WHERE id = COALESCE(sqlc.arg(id),id)
9+
RETURNING a.id, a.address_line, a.region, a.city
10+
),
11+
12+
t2 AS (
13+
UPDATE "user_address"
14+
SET
15+
default_address = COALESCE(sqlc.narg(default_address),default_address)
16+
WHERE
17+
user_id = COALESCE(sqlc.arg(user_id),user_id)
18+
AND address_id = COALESCE(sqlc.arg(address_id),address_id)
19+
RETURNING user_id, address_id, default_address
20+
)
21+
22+
SELECT
23+
user_id,
24+
address_id,
25+
default_address,
26+
address_line,
27+
region,
28+
city From t1,t2;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
CREATE TABLE "user" (
2+
"id" bigserial PRIMARY KEY NOT NULL,
3+
"username" varchar NOT NULL,
4+
"email" varchar UNIQUE NOT NULL,
5+
"password" varchar NOT NULL,
6+
"telephone" int NOT NULL DEFAULT 0,
7+
"default_payment" bigint,
8+
"created_at" timestamptz NOT NULL DEFAULT (now()),
9+
"updated_at" timestamptz NOT NULL DEFAULT '0001-01-01 00:00:00Z'
10+
);
11+
12+
CREATE TABLE "address" (
13+
"id" bigserial PRIMARY KEY NOT NULL,
14+
"address_line" varchar NOT NULL,
15+
"region" varchar NOT NULL,
16+
"city" varchar NOT NULL,
17+
"created_at" timestamptz NOT NULL DEFAULT (now()),
18+
"updated_at" timestamptz NOT NULL DEFAULT '0001-01-01 00:00:00Z'
19+
);
20+
21+
CREATE TABLE "user_address" (
22+
"user_id" bigint NOT NULL,
23+
"address_id" bigint UNIQUE NOT NULL,
24+
"default_address" bigint,
25+
"created_at" timestamptz NOT NULL DEFAULT (now()),
26+
"updated_at" timestamptz NOT NULL DEFAULT '0001-01-01 00:00:00Z'
27+
);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version: "2"
2+
sql:
3+
- engine: "postgresql"
4+
schema: "schema.sql"
5+
queries: "query.sql"
6+
gen:
7+
go:
8+
package: "querytest"
9+
out: "go"
10+
sql_package: "pgx/v5"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://github.com/sqlc-dev/sqlc/issues/1917
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"contexts": ["managed-db"]
3+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- name: SelectOne :one
2+
SELECT 1;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CREATE TABLE test_table (
2+
id STRING
3+
);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version: "2"
2+
sql:
3+
- engine: "postgresql"
4+
schema: "schema.sql"
5+
queries: "query.sql"
6+
gen:
7+
go:
8+
package: "querytest"
9+
out: "go"
10+
sql_package: "pgx/v5"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# package querytest
2+
query.sql:1:1: rpc error: code = FailedPrecondition desc = type "string" does not exist (42704)
3+
CREATE TABLE test_table (
4+
id STRING
5+
);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://github.com/sqlc-dev/sqlc/issues/1545
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"contexts": ["managed-db"]
3+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- name: GetTotalEarned :one
2+
SELECT COALESCE(SUM(earned), 0) as total_earned
3+
FROM grouped_kpis
4+
WHERE day = @day;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CREATE TABLE kpis (
2+
ts TIMESTAMPTZ,
3+
event_id TEXT NOT NULL
4+
);
5+
6+
CREATE MATERIALIZED VIEW IF NOT EXISTS grouped_kpis AS
7+
SELECT date_trunc('1 day', ts) as day, COUNT(*)
8+
FROM kpis
9+
GROUP BY 1;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version: "2"
2+
sql:
3+
- engine: "postgresql"
4+
schema: "schema.sql"
5+
queries: "query.sql"
6+
gen:
7+
go:
8+
package: "querytest"
9+
out: "go"
10+
sql_package: "pgx/v5"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# package querytest
2+
query.sql:2:21: column "earned" does not exist
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://github.com/sqlc-dev/sqlc/issues/1714
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"contexts": ["managed-db"]
3+
}

internal/endtoend/testdata/delete_using/postgresql/pgx/go/db.go

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/delete_using/postgresql/pgx/go/models.go

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)