fix(sql): allow quoted keyword table navigation

This commit is contained in:
zipg authored and GitHub committed 2026-07-08 17:51:03 +08:00
1 parent ae627de320
commit 488f661bf3
3 files changed
+49 -14

No files matched your search

@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest";
import { extractIdentifierAt, matchTable, splitQualifiedIdentifier } from "@/lib/sql/sqlNavigation";
import { extractIdentifierAt, extractIdentifierDetailsAt, isSqlKeyword, matchTable, splitQualifiedIdentifier } from "@/lib/sql/sqlNavigation";
describe("extractIdentifierAt", () => {
it("extracts unquoted qualified identifiers", () => {
@@ -15,6 +15,27 @@ describe("extractIdentifierAt", () => {
expect(extractIdentifierAt(sql, sql.indexOf("MAAC00"))).toBe("MAAC00.Accounts");
});
it("preserves quote metadata for quoted keyword identifiers", () => {
const sql = "SELECT * FROM `group` LIMIT 100;";
expect(extractIdentifierDetailsAt(sql, sql.indexOf("group"))).toEqual({
identifier: "group",
quoted: true,
});
expect(matchTable(extractIdentifierAt(sql, sql.indexOf("group")) ?? "", [{ name: "group" }])).toEqual({ name: "group" });
});
it("marks unquoted keyword identifiers as unquoted", () => {
const sql = "SELECT dept, COUNT(*) FROM users GROUP BY dept;";
const extracted = extractIdentifierDetailsAt(sql, sql.indexOf("GROUP"));
expect(extracted).toEqual({
identifier: "GROUP",
quoted: false,
});
expect(extracted && isSqlKeyword(extracted.identifier)).toBe(true);
});
it("extracts double-quoted qualified identifiers", () => {
const sql = 'select * from "MAAC00"."Accounts"';