fix(sql): support brace placeholders in formatter
This commit is contained in:
1 parent
9234c33e24
commit
c80313eed2
4 files changed
+46
-3
No files matched your search
@@ -14,6 +14,18 @@ describe("sqlFormatter", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("preserves DBX brace placeholders in generic and MySQL SQL", async () => {
|
||||
const sql = "SELECT ${x} AS shell_value, #{x} AS mybatis_value, '${date}' AS quoted_value";
|
||||
|
||||
for (const dialect of ["generic", "mysql"] as const) {
|
||||
const formatted = await formatSqlText(sql, dialect);
|
||||
|
||||
expect(formatted).toContain("${x}");
|
||||
expect(formatted).toContain("#{x}");
|
||||
expect(formatted).toContain("'${date}'");
|
||||
}
|
||||
});
|
||||
|
||||
it("falls back to the postgres formatter when the generic dialect cannot parse SQL", async () => {
|
||||
const formatted = await formatSqlText("SELECT 1::int AS id;", "generic");
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { DEFAULT_SQL_FORMATTER_SETTINGS, parseSqlFormatterConfig, serializeSqlFormatterConfig } from "@/lib/sql/sqlFormatterConfig";
|
||||
import { DEFAULT_SQL_FORMATTER_SETTINGS, parseSqlFormatterConfig, serializeSqlFormatterConfig, sqlFormatterOptions } from "@/lib/sql/sqlFormatterConfig";
|
||||
|
||||
describe("sqlFormatterConfig shortcut storage", () => {
|
||||
it("does not serialize JSON editor shortcut settings", () => {
|
||||
@@ -23,4 +23,20 @@ describe("sqlFormatterConfig shortcut storage", () => {
|
||||
|
||||
expect(result.ok).toBe(true);
|
||||
});
|
||||
|
||||
it("merges DBX custom parameter types with user paramTypes", () => {
|
||||
const options = sqlFormatterOptions({
|
||||
paramTypes: {
|
||||
positional: false,
|
||||
named: ["@"],
|
||||
custom: [{ regex: String.raw`\{\{[^}]+\}\}` }],
|
||||
},
|
||||
});
|
||||
|
||||
expect(options.paramTypes).toEqual({
|
||||
positional: false,
|
||||
named: ["@"],
|
||||
custom: [{ regex: String.raw`\{\{[^}]+\}\}` }, { regex: String.raw`\$\{[^}]+\}` }, { regex: String.raw`#\{[^}]+\}` }],
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user