snapshot of https://github.com/sqlc-dev/sqlc.git (main, 2026-09-16; blobs > 131072B omitted)
Some checks failed
kotlin / test (push) Has been skipped
python / test (push) Has been skipped
typescript / test (push) Has been skipped
go / build darwin/amd64 (push) Has been cancelled
go / build linux/amd64 (push) Has been cancelled
go / build windows/amd64 (push) Has been cancelled
go / build darwin/arm64 (push) Has been cancelled
go / build linux/arm64 (push) Has been cancelled
go / build windows/arm64 (push) Has been cancelled
go / test (push) Has been cancelled
go / vuln_check (push) Has been cancelled
Some checks failed
kotlin / test (push) Has been skipped
python / test (push) Has been skipped
typescript / test (push) Has been skipped
go / build darwin/amd64 (push) Has been cancelled
go / build linux/amd64 (push) Has been cancelled
go / build windows/amd64 (push) Has been cancelled
go / build darwin/arm64 (push) Has been cancelled
go / build linux/arm64 (push) Has been cancelled
go / build windows/arm64 (push) Has been cancelled
go / test (push) Has been cancelled
go / vuln_check (push) Has been cancelled
This commit is contained in:
1
internal/endtoend/testdata/cte_update_multiple/issue.md
vendored
Normal file
1
internal/endtoend/testdata/cte_update_multiple/issue.md
vendored
Normal file
@@ -0,0 +1 @@
|
||||
https://github.com/sqlc-dev/sqlc/issues/1916
|
||||
3
internal/endtoend/testdata/cte_update_multiple/postgresql/pgx/exec.json
vendored
Normal file
3
internal/endtoend/testdata/cte_update_multiple/postgresql/pgx/exec.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"contexts": ["managed-db"]
|
||||
}
|
||||
32
internal/endtoend/testdata/cte_update_multiple/postgresql/pgx/go/db.go
vendored
Normal file
32
internal/endtoend/testdata/cte_update_multiple/postgresql/pgx/go/db.go
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
|
||||
package querytest
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgconn"
|
||||
)
|
||||
|
||||
type DBTX interface {
|
||||
Exec(context.Context, string, ...any) (pgconn.CommandTag, error)
|
||||
Query(context.Context, string, ...any) (pgx.Rows, error)
|
||||
QueryRow(context.Context, string, ...any) pgx.Row
|
||||
}
|
||||
|
||||
func New(db DBTX) *Queries {
|
||||
return &Queries{db: db}
|
||||
}
|
||||
|
||||
type Queries struct {
|
||||
db DBTX
|
||||
}
|
||||
|
||||
func (q *Queries) WithTx(tx pgx.Tx) *Queries {
|
||||
return &Queries{
|
||||
db: tx,
|
||||
}
|
||||
}
|
||||
37
internal/endtoend/testdata/cte_update_multiple/postgresql/pgx/go/models.go
vendored
Normal file
37
internal/endtoend/testdata/cte_update_multiple/postgresql/pgx/go/models.go
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
|
||||
package querytest
|
||||
|
||||
import (
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
type Address struct {
|
||||
ID int64
|
||||
AddressLine string
|
||||
Region string
|
||||
City string
|
||||
CreatedAt pgtype.Timestamptz
|
||||
UpdatedAt pgtype.Timestamptz
|
||||
}
|
||||
|
||||
type User struct {
|
||||
ID int64
|
||||
Username string
|
||||
Email string
|
||||
Password string
|
||||
Telephone int32
|
||||
DefaultPayment pgtype.Int8
|
||||
CreatedAt pgtype.Timestamptz
|
||||
UpdatedAt pgtype.Timestamptz
|
||||
}
|
||||
|
||||
type UserAddress struct {
|
||||
UserID int64
|
||||
AddressID int64
|
||||
DefaultAddress pgtype.Int8
|
||||
CreatedAt pgtype.Timestamptz
|
||||
UpdatedAt pgtype.Timestamptz
|
||||
}
|
||||
83
internal/endtoend/testdata/cte_update_multiple/postgresql/pgx/go/query.sql.go
vendored
Normal file
83
internal/endtoend/testdata/cte_update_multiple/postgresql/pgx/go/query.sql.go
vendored
Normal file
@@ -0,0 +1,83 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
// source: query.sql
|
||||
|
||||
package querytest
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const updateUserAddressWithAddress = `-- name: UpdateUserAddressWithAddress :one
|
||||
WITH t1 AS (
|
||||
UPDATE "address" as a
|
||||
SET
|
||||
address_line = COALESCE($1,address_line),
|
||||
region = COALESCE($2,region),
|
||||
city= COALESCE($3,city)
|
||||
WHERE id = COALESCE($4,id)
|
||||
RETURNING a.id, a.address_line, a.region, a.city
|
||||
),
|
||||
|
||||
t2 AS (
|
||||
UPDATE "user_address"
|
||||
SET
|
||||
default_address = COALESCE($5,default_address)
|
||||
WHERE
|
||||
user_id = COALESCE($6,user_id)
|
||||
AND address_id = COALESCE($7,address_id)
|
||||
RETURNING user_id, address_id, default_address
|
||||
)
|
||||
|
||||
SELECT
|
||||
user_id,
|
||||
address_id,
|
||||
default_address,
|
||||
address_line,
|
||||
region,
|
||||
city From t1,t2
|
||||
`
|
||||
|
||||
type UpdateUserAddressWithAddressParams struct {
|
||||
AddressLine pgtype.Text
|
||||
Region pgtype.Text
|
||||
City pgtype.Text
|
||||
ID pgtype.Int8
|
||||
DefaultAddress pgtype.Int8
|
||||
UserID pgtype.Int8
|
||||
AddressID pgtype.Int8
|
||||
}
|
||||
|
||||
type UpdateUserAddressWithAddressRow struct {
|
||||
UserID int64
|
||||
AddressID int64
|
||||
DefaultAddress pgtype.Int8
|
||||
AddressLine string
|
||||
Region string
|
||||
City string
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateUserAddressWithAddress(ctx context.Context, arg UpdateUserAddressWithAddressParams) (UpdateUserAddressWithAddressRow, error) {
|
||||
row := q.db.QueryRow(ctx, updateUserAddressWithAddress,
|
||||
arg.AddressLine,
|
||||
arg.Region,
|
||||
arg.City,
|
||||
arg.ID,
|
||||
arg.DefaultAddress,
|
||||
arg.UserID,
|
||||
arg.AddressID,
|
||||
)
|
||||
var i UpdateUserAddressWithAddressRow
|
||||
err := row.Scan(
|
||||
&i.UserID,
|
||||
&i.AddressID,
|
||||
&i.DefaultAddress,
|
||||
&i.AddressLine,
|
||||
&i.Region,
|
||||
&i.City,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
28
internal/endtoend/testdata/cte_update_multiple/postgresql/pgx/query.sql
vendored
Normal file
28
internal/endtoend/testdata/cte_update_multiple/postgresql/pgx/query.sql
vendored
Normal file
@@ -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;
|
||||
27
internal/endtoend/testdata/cte_update_multiple/postgresql/pgx/schema.sql
vendored
Normal file
27
internal/endtoend/testdata/cte_update_multiple/postgresql/pgx/schema.sql
vendored
Normal file
@@ -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'
|
||||
);
|
||||
10
internal/endtoend/testdata/cte_update_multiple/postgresql/pgx/sqlc.yaml
vendored
Normal file
10
internal/endtoend/testdata/cte_update_multiple/postgresql/pgx/sqlc.yaml
vendored
Normal file
@@ -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"
|
||||
Reference in New Issue
Block a user