Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
提交
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion internal/cmd/fmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ func newQueryFormatter(engine config.Engine) queryFormatter {
case config.EngineSQLite:
return sqlite.新建Parser()
case config.EngineMySQL:
return dolphin.新建Parser()
// The format parser preserves identifier case and proves every
// statement via Fingerprint, the way oliphant does for PostgreSQL.
return dolphin.新建FormatParser()
default:
return nil
}
Expand Down
31 changes: 31 additions & 0 deletions internal/endtoend/testdata/fmt/mysql/query.sql
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,34 @@ insert into authors (
) 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);
19 changes: 18 additions & 1 deletion internal/endtoend/testdata/fmt/mysql/stdout.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

-- name: CastUnsigned :one
SELECT CAST(id AS UNSIGNED) FROM authors LIMIT 1;
@@ -34,8 +39,5 @@
@@ -34,14 +39,11 @@
SELECT id FROM authors LIMIT 1;

-- name: CreateAuthor :execresult
Expand All @@ -54,3 +54,20 @@
-) 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 changes: 4 additions & 1 deletion internal/endtoend/testdata/fmt/postgresql/query.sql
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@ WHERE id > $1;
-- name: 搜索Authors :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
DELETE FROM authors WHERE id = @id
4 changes: 2 additions & 2 deletions internal/endtoend/testdata/fmt/postgresql/stdout.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
FROM authors
WHERE id > $1;

@@ -27,4 +27,4 @@
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;
@@ -30,4 +30,4 @@
SELECT name FROM authors WHERE name = @slug AND @filter::bool;

-- name: DeleteAuthor :exec
-DELETE FROM authors WHERE id = @id
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading