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:
5
internal/endtoend/testdata/fmt/mysql/exec.json
vendored
Normal file
5
internal/endtoend/testdata/fmt/mysql/exec.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"command": "fmt",
|
||||
"args": ["--diff"],
|
||||
"contexts": ["base"]
|
||||
}
|
||||
72
internal/endtoend/testdata/fmt/mysql/query.sql
vendored
Normal file
72
internal/endtoend/testdata/fmt/mysql/query.sql
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
-- name: GetAuthor :one
|
||||
select id,name , bio from authors
|
||||
where id = ? limit 1;
|
||||
|
||||
# hash comment
|
||||
-- name: ListAuthors :many
|
||||
SELECT id, name, bio FROM authors
|
||||
ORDER BY name DESC;
|
||||
|
||||
-- name: PickyQuery :many
|
||||
SELECT id, -- the primary key
|
||||
name,
|
||||
-- computed downstream
|
||||
bio
|
||||
FROM authors
|
||||
-- soft-deleted rows are filtered
|
||||
WHERE bio IS NOT NULL
|
||||
AND id > ?;
|
||||
|
||||
-- name: InlineBlock :many
|
||||
SELECT /* inline note */ id, name FROM authors ORDER BY name;
|
||||
|
||||
-- name: CountSigils :one
|
||||
SELECT count(*) FROM authors
|
||||
WHERE id <> ? AND name <> @user_name; # session variable stays
|
||||
|
||||
-- name: CastUnsigned :one
|
||||
SELECT CAST(id AS UNSIGNED) FROM authors LIMIT 1;
|
||||
|
||||
-- name: FirstTwin :one
|
||||
SELECT id FROM authors LIMIT 1;
|
||||
|
||||
-- name: SecondTwin :one
|
||||
SELECT id FROM authors LIMIT 1;
|
||||
|
||||
-- name: CreateAuthor :execresult
|
||||
insert into authors (
|
||||
name, bio
|
||||
) values (
|
||||
?, ?
|
||||
);
|
||||
|
||||
-- name: CasePreserved :many
|
||||
SELECT ID, Name FROM Authors WHERE Name <> '' ORDER BY Name;
|
||||
|
||||
-- name: LiteralsSurvive :one
|
||||
SELECT true AS t, false AS f, 1.50 AS score, CASE WHEN name = '' THEN NULL ELSE name END AS n FROM authors LIMIT 1;
|
||||
|
||||
-- name: DistinctNames :many
|
||||
SELECT DISTINCT name FROM authors;
|
||||
|
||||
-- name: UnionOrdered :many
|
||||
SELECT name AS foo FROM authors
|
||||
UNION
|
||||
SELECT bio AS foo FROM authors
|
||||
ORDER BY foo;
|
||||
|
||||
-- name: ConcatNames :many
|
||||
SELECT group_concat(DISTINCT name ORDER BY name DESC SEPARATOR ' ') FROM authors GROUP BY bio;
|
||||
|
||||
-- name: Hinted :one
|
||||
SELECT /*+ MAX_EXECUTION_TIME(1000) */ id FROM authors LIMIT 1;
|
||||
|
||||
-- name: UpdateWithJoin :exec
|
||||
UPDATE authors AS a JOIN authors AS p ON p.id = a.id
|
||||
SET a.name = ?
|
||||
WHERE p.bio IS NOT NULL;
|
||||
|
||||
-- name: ShowWarnings :many
|
||||
SHOW WARNINGS;
|
||||
|
||||
CREATE TABLE scores (points decimal(10, 5), views bigint unsigned NOT NULL);
|
||||
5
internal/endtoend/testdata/fmt/mysql/schema.sql
vendored
Normal file
5
internal/endtoend/testdata/fmt/mysql/schema.sql
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
CREATE TABLE authors (
|
||||
id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
||||
name varchar(255) NOT NULL,
|
||||
bio text
|
||||
);
|
||||
9
internal/endtoend/testdata/fmt/mysql/sqlc.yaml
vendored
Normal file
9
internal/endtoend/testdata/fmt/mysql/sqlc.yaml
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
version: "2"
|
||||
sql:
|
||||
- engine: "mysql"
|
||||
schema: "schema.sql"
|
||||
queries: "query.sql"
|
||||
gen:
|
||||
go:
|
||||
package: "querytest"
|
||||
out: "go"
|
||||
73
internal/endtoend/testdata/fmt/mysql/stdout.txt
vendored
Normal file
73
internal/endtoend/testdata/fmt/mysql/stdout.txt
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
--- a/query.sql
|
||||
+++ b/query.sql
|
||||
@@ -1,6 +1,8 @@
|
||||
-- name: GetAuthor :one
|
||||
+SELECT id, name, bio
|
||||
+FROM authors
|
||||
+WHERE id = ?
|
||||
+LIMIT 1;
|
||||
-select id,name , bio from authors
|
||||
-where id = ? limit 1;
|
||||
|
||||
# hash comment
|
||||
-- name: ListAuthors :many
|
||||
@@ -7,4 +9,5 @@
|
||||
+SELECT id, name, bio
|
||||
+FROM authors
|
||||
-SELECT id, name, bio FROM authors
|
||||
ORDER BY name DESC;
|
||||
|
||||
-- name: PickyQuery :many
|
||||
@@ -11,7 +14,8 @@
|
||||
+SELECT
|
||||
+ id, -- the primary key
|
||||
+ name,
|
||||
+ -- computed downstream
|
||||
+ bio
|
||||
-SELECT id, -- the primary key
|
||||
- name,
|
||||
- -- computed downstream
|
||||
- bio
|
||||
FROM authors
|
||||
-- soft-deleted rows are filtered
|
||||
WHERE bio IS NOT NULL
|
||||
@@ -21,8 +25,9 @@
|
||||
SELECT /* inline note */ id, name FROM authors ORDER BY name;
|
||||
|
||||
-- name: CountSigils :one
|
||||
+SELECT count(*)
|
||||
+FROM authors
|
||||
+WHERE id != ? AND name != @user_name; # session variable stays
|
||||
-SELECT count(*) FROM authors
|
||||
-WHERE id <> ? AND name <> @user_name; # session variable stays
|
||||
|
||||
-- name: CastUnsigned :one
|
||||
SELECT CAST(id AS UNSIGNED) FROM authors LIMIT 1;
|
||||
@@ -34,14 +39,11 @@
|
||||
SELECT id FROM authors LIMIT 1;
|
||||
|
||||
-- name: CreateAuthor :execresult
|
||||
+INSERT INTO authors (name, bio)
|
||||
+VALUES (?, ?);
|
||||
-insert into authors (
|
||||
- name, bio
|
||||
-) values (
|
||||
- ?, ?
|
||||
-);
|
||||
|
||||
-- name: CasePreserved :many
|
||||
+SELECT ID, Name FROM Authors WHERE Name != '' ORDER BY Name;
|
||||
-SELECT ID, Name FROM Authors WHERE Name <> '' ORDER BY Name;
|
||||
|
||||
-- name: LiteralsSurvive :one
|
||||
SELECT true AS t, false AS f, 1.50 AS score, CASE WHEN name = '' THEN NULL ELSE name END AS n FROM authors LIMIT 1;
|
||||
@@ -62,7 +64,8 @@
|
||||
SELECT /*+ MAX_EXECUTION_TIME(1000) */ id FROM authors LIMIT 1;
|
||||
|
||||
-- name: UpdateWithJoin :exec
|
||||
+UPDATE authors AS a
|
||||
+JOIN authors AS p ON p.id = a.id
|
||||
-UPDATE authors AS a JOIN authors AS p ON p.id = a.id
|
||||
SET a.name = ?
|
||||
WHERE p.bio IS NOT NULL;
|
||||
|
||||
5
internal/endtoend/testdata/fmt/postgresql/exec.json
vendored
Normal file
5
internal/endtoend/testdata/fmt/postgresql/exec.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"command": "fmt",
|
||||
"args": ["--diff"],
|
||||
"contexts": ["base"]
|
||||
}
|
||||
33
internal/endtoend/testdata/fmt/postgresql/query.sql
vendored
Normal file
33
internal/endtoend/testdata/fmt/postgresql/query.sql
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
-- name: GetAuthor :one
|
||||
select id,name , bio
|
||||
from authors
|
||||
where id = $1 limit 1; -- the primary lookup
|
||||
|
||||
/* This listing powers the admin page.
|
||||
Keep it ordered by name so the UI stays stable. */
|
||||
-- name: ListAuthors :many
|
||||
SELECT id, name, bio FROM authors
|
||||
ORDER BY name;
|
||||
|
||||
-- name: CreateAuthor :one
|
||||
INSERT INTO authors (
|
||||
name, bio
|
||||
) VALUES (
|
||||
$1, $2
|
||||
)
|
||||
RETURNING *;
|
||||
|
||||
-- name: PickyQuery :many
|
||||
SELECT id, -- the primary key
|
||||
name
|
||||
FROM authors
|
||||
WHERE id > $1;
|
||||
|
||||
-- name: SearchAuthors :many
|
||||
SELECT id, name, bio, created_at FROM authors WHERE name LIKE $1 AND bio IS NOT NULL AND id > $2 AND name <> $3 ORDER BY name, id LIMIT $4;
|
||||
|
||||
-- name: AtParamsGlued :many
|
||||
SELECT name FROM authors WHERE name = @slug AND @filter::bool;
|
||||
|
||||
-- name: DeleteAuthor :exec
|
||||
DELETE FROM authors WHERE id = @id
|
||||
6
internal/endtoend/testdata/fmt/postgresql/schema.sql
vendored
Normal file
6
internal/endtoend/testdata/fmt/postgresql/schema.sql
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
CREATE TABLE authors (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
name text NOT NULL,
|
||||
bio text,
|
||||
created_at timestamptz NOT NULL DEFAULT now()
|
||||
);
|
||||
9
internal/endtoend/testdata/fmt/postgresql/sqlc.yaml
vendored
Normal file
9
internal/endtoend/testdata/fmt/postgresql/sqlc.yaml
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
version: "2"
|
||||
sql:
|
||||
- engine: "postgresql"
|
||||
schema: "schema.sql"
|
||||
queries: "query.sql"
|
||||
gen:
|
||||
go:
|
||||
package: "querytest"
|
||||
out: "go"
|
||||
48
internal/endtoend/testdata/fmt/postgresql/stdout.txt
vendored
Normal file
48
internal/endtoend/testdata/fmt/postgresql/stdout.txt
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
--- a/query.sql
|
||||
+++ b/query.sql
|
||||
@@ -1,7 +1,8 @@
|
||||
-- name: GetAuthor :one
|
||||
-select id,name , bio
|
||||
-from authors
|
||||
-where id = $1 limit 1; -- the primary lookup
|
||||
+SELECT id, name, bio
|
||||
+FROM authors
|
||||
+WHERE id = $1
|
||||
+LIMIT 1; -- the primary lookup
|
||||
|
||||
/* This listing powers the admin page.
|
||||
Keep it ordered by name so the UI stays stable. */
|
||||
@@ -8,5 +9,6 @@
|
||||
-- name: ListAuthors :many
|
||||
-SELECT id, name, bio FROM authors
|
||||
+SELECT id, name, bio
|
||||
+FROM authors
|
||||
ORDER BY name;
|
||||
|
||||
-- name: CreateAuthor :one
|
||||
@@ -13,8 +15,5 @@
|
||||
-INSERT INTO authors (
|
||||
- name, bio
|
||||
-) VALUES (
|
||||
- $1, $2
|
||||
-)
|
||||
+INSERT INTO authors (name, bio)
|
||||
+VALUES ($1, $2)
|
||||
RETURNING *;
|
||||
|
||||
-- name: PickyQuery :many
|
||||
@@ -21,5 +20,6 @@
|
||||
-SELECT id, -- the primary key
|
||||
- name
|
||||
+SELECT
|
||||
+ id, -- the primary key
|
||||
+ name
|
||||
FROM authors
|
||||
WHERE id > $1;
|
||||
|
||||
@@ -30,4 +30,4 @@
|
||||
SELECT name FROM authors WHERE name = @slug AND @filter::bool;
|
||||
|
||||
-- name: DeleteAuthor :exec
|
||||
-DELETE FROM authors WHERE id = @id
|
||||
+DELETE FROM authors WHERE id = @id;
|
||||
5
internal/endtoend/testdata/fmt/sqlite/exec.json
vendored
Normal file
5
internal/endtoend/testdata/fmt/sqlite/exec.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"command": "fmt",
|
||||
"args": ["--diff"],
|
||||
"contexts": ["base"]
|
||||
}
|
||||
107
internal/endtoend/testdata/fmt/sqlite/query.sql
vendored
Normal file
107
internal/endtoend/testdata/fmt/sqlite/query.sql
vendored
Normal file
@@ -0,0 +1,107 @@
|
||||
-- name: GetAuthor :one
|
||||
select id,name , bio from authors
|
||||
where id = ? limit 1;
|
||||
|
||||
-- name: PickyQuery :many
|
||||
SELECT id, -- the primary key
|
||||
name,
|
||||
-- computed downstream
|
||||
bio
|
||||
FROM authors
|
||||
-- soft-deleted rows are filtered
|
||||
WHERE bio IS NOT NULL
|
||||
AND id > ?;
|
||||
|
||||
-- name: InlineBlock :many
|
||||
SELECT /* inline note */ id, name FROM authors ORDER BY name;
|
||||
|
||||
-- name: ListAuthors :many
|
||||
SELECT id, name, bio FROM authors
|
||||
ORDER BY name;
|
||||
|
||||
-- name: GetEvent :one
|
||||
SELECT "EventName", "order"
|
||||
FROM "Events" WHERE id = ? LIMIT 1;
|
||||
|
||||
-- name: CountSigils :one
|
||||
SELECT count(*) FROM authors
|
||||
WHERE id <> @at_param AND id <> :colon_param AND id <> $dollar_param;
|
||||
|
||||
-- name: TopAuthors :many
|
||||
WITH ranked AS (
|
||||
SELECT id, name FROM authors
|
||||
)
|
||||
SELECT * FROM ranked;
|
||||
|
||||
-- name: AddAuthor :exec
|
||||
INSERT INTO authors (name, bio)
|
||||
VALUES (?, ?);
|
||||
|
||||
-- name: MakeScratch :exec
|
||||
CREATE TABLE scratch (
|
||||
id INTEGER NOT NULL,
|
||||
label TEXT
|
||||
);
|
||||
|
||||
-- name: MakeMeasurements :exec
|
||||
CREATE TABLE IF NOT EXISTS measurements (
|
||||
id INTEGER PRIMARY KEY,
|
||||
label VARYING CHARACTER(120),
|
||||
ratio DECIMAL(10,5),
|
||||
note
|
||||
);
|
||||
|
||||
-- name: KeepAutoinc :exec
|
||||
CREATE TABLE counters (id INTEGER PRIMARY KEY AUTOINCREMENT, hits INTEGER DEFAULT 0);
|
||||
|
||||
-- name: CastLabel :one
|
||||
SELECT CAST(bio AS VARYING CHARACTER(120)) FROM authors LIMIT 1;
|
||||
|
||||
-- name: MakeSearchIndex :exec
|
||||
CREATE VIRTUAL TABLE IF NOT EXISTS notes_fts USING fts5(body, tag UNINDEXED, tokenize = 'porter');
|
||||
|
||||
-- name: MakeRecipeIndex :exec
|
||||
CREATE VIRTUAL TABLE recipes_fts USING fts5(
|
||||
name,
|
||||
ingredients
|
||||
);
|
||||
|
||||
-- name: LoginName :one
|
||||
SELECT COALESCE(bio, '') AS login FROM authors WHERE id = ? LIMIT 1;
|
||||
|
||||
-- name: SpelledJoins :many
|
||||
SELECT a.id
|
||||
FROM authors AS a
|
||||
INNER JOIN authors AS b ON a.id = b.id
|
||||
LEFT OUTER JOIN authors AS c ON a.id = c.id
|
||||
WHERE a.id != ? AND b.id == ? AND c.id <> ?;
|
||||
|
||||
-- name: CommaJoin :one
|
||||
SELECT count(*) FROM authors AS a, authors AS b WHERE a.id = b.id;
|
||||
|
||||
-- name: PlannerHint :many
|
||||
SELECT a.id FROM authors AS a CROSS JOIN authors AS b;
|
||||
|
||||
-- name: NumberedParams :many
|
||||
SELECT id FROM authors WHERE name = ?2 AND bio = ?1;
|
||||
|
||||
-- name: NewestAndOldest :many
|
||||
SELECT id FROM authors
|
||||
UNION
|
||||
SELECT id FROM authors;
|
||||
|
||||
-- name: QuickUnion :many
|
||||
SELECT id FROM authors UNION ALL SELECT id FROM authors;
|
||||
|
||||
-- name: EnableForeignKeys :exec
|
||||
PRAGMA foreign_keys = 1;
|
||||
|
||||
-- name: UpsertAuthor :exec
|
||||
INSERT INTO authors (id, name)
|
||||
VALUES (?, ?)
|
||||
ON CONFLICT (id) DO UPDATE SET
|
||||
name = excluded.name
|
||||
WHERE excluded.name <> '';
|
||||
|
||||
-- name: QuickUpsert :exec
|
||||
INSERT INTO authors (id, name) VALUES (?, ?) ON CONFLICT (id) DO UPDATE SET name = excluded.name;
|
||||
11
internal/endtoend/testdata/fmt/sqlite/schema.sql
vendored
Normal file
11
internal/endtoend/testdata/fmt/sqlite/schema.sql
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
CREATE TABLE authors (
|
||||
id integer PRIMARY KEY,
|
||||
name text NOT NULL,
|
||||
bio text
|
||||
);
|
||||
|
||||
CREATE TABLE "Events" (
|
||||
id integer PRIMARY KEY,
|
||||
"EventName" text NOT NULL,
|
||||
"order" integer NOT NULL
|
||||
);
|
||||
9
internal/endtoend/testdata/fmt/sqlite/sqlc.yaml
vendored
Normal file
9
internal/endtoend/testdata/fmt/sqlite/sqlc.yaml
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
version: "2"
|
||||
sql:
|
||||
- engine: "sqlite"
|
||||
schema: "schema.sql"
|
||||
queries: "query.sql"
|
||||
gen:
|
||||
go:
|
||||
package: "querytest"
|
||||
out: "go"
|
||||
84
internal/endtoend/testdata/fmt/sqlite/stdout.txt
vendored
Normal file
84
internal/endtoend/testdata/fmt/sqlite/stdout.txt
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
--- a/query.sql
|
||||
+++ b/query.sql
|
||||
@@ -1,12 +1,15 @@
|
||||
-- name: GetAuthor :one
|
||||
+SELECT id, name, bio
|
||||
+FROM authors
|
||||
+WHERE id = ?
|
||||
+LIMIT 1;
|
||||
-select id,name , bio from authors
|
||||
-where id = ? limit 1;
|
||||
|
||||
-- name: PickyQuery :many
|
||||
+SELECT
|
||||
+ id, -- the primary key
|
||||
+ name,
|
||||
+ -- computed downstream
|
||||
+ bio
|
||||
-SELECT id, -- the primary key
|
||||
- name,
|
||||
- -- computed downstream
|
||||
- bio
|
||||
FROM authors
|
||||
-- soft-deleted rows are filtered
|
||||
WHERE bio IS NOT NULL
|
||||
@@ -16,7 +19,8 @@
|
||||
SELECT /* inline note */ id, name FROM authors ORDER BY name;
|
||||
|
||||
-- name: ListAuthors :many
|
||||
+SELECT id, name, bio
|
||||
+FROM authors
|
||||
-SELECT id, name, bio FROM authors
|
||||
ORDER BY name;
|
||||
|
||||
-- name: GetEvent :one
|
||||
@@ -23,8 +27,11 @@
|
||||
SELECT "EventName", "order"
|
||||
+FROM "Events"
|
||||
+WHERE id = ?
|
||||
+LIMIT 1;
|
||||
-FROM "Events" WHERE id = ? LIMIT 1;
|
||||
|
||||
-- name: CountSigils :one
|
||||
+SELECT count(*)
|
||||
+FROM authors
|
||||
-SELECT count(*) FROM authors
|
||||
WHERE id <> @at_param AND id <> :colon_param AND id <> $dollar_param;
|
||||
|
||||
-- name: TopAuthors :many
|
||||
@@ -46,7 +53,7 @@
|
||||
-- name: MakeMeasurements :exec
|
||||
CREATE TABLE IF NOT EXISTS measurements (
|
||||
id INTEGER PRIMARY KEY,
|
||||
+ label VARYING CHARACTER(120),
|
||||
- label VARYING CHARACTER(120),
|
||||
ratio DECIMAL(10,5),
|
||||
note
|
||||
);
|
||||
@@ -58,7 +65,7 @@
|
||||
SELECT CAST(bio AS VARYING CHARACTER(120)) FROM authors LIMIT 1;
|
||||
|
||||
-- name: MakeSearchIndex :exec
|
||||
+CREATE VIRTUAL TABLE IF NOT EXISTS notes_fts USING fts5(body, tag UNINDEXED, tokenize = 'porter');
|
||||
-CREATE VIRTUAL TABLE IF NOT EXISTS notes_fts USING fts5(body, tag UNINDEXED, tokenize = 'porter');
|
||||
|
||||
-- name: MakeRecipeIndex :exec
|
||||
CREATE VIRTUAL TABLE recipes_fts USING fts5(
|
||||
@@ -67,7 +74,7 @@
|
||||
);
|
||||
|
||||
-- name: LoginName :one
|
||||
+SELECT coalesce(bio, '') AS login FROM authors WHERE id = ? LIMIT 1;
|
||||
-SELECT COALESCE(bio, '') AS login FROM authors WHERE id = ? LIMIT 1;
|
||||
|
||||
-- name: SpelledJoins :many
|
||||
SELECT a.id
|
||||
@@ -74,6 +81,6 @@
|
||||
FROM authors AS a
|
||||
+JOIN authors AS b ON a.id = b.id
|
||||
+LEFT JOIN authors AS c ON a.id = c.id
|
||||
-INNER JOIN authors AS b ON a.id = b.id
|
||||
-LEFT OUTER JOIN authors AS c ON a.id = c.id
|
||||
WHERE a.id != ? AND b.id == ? AND c.id <> ?;
|
||||
|
||||
-- name: CommaJoin :one
|
||||
Reference in New Issue
Block a user