UNPKG

rawsql-ts

Version:

High-performance SQL parser and AST analyzer written in TypeScript. Provides fast parsing and advanced transformation capabilities.

35 lines 1.61 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.tableNameVariants = exports.normalizeTableName = void 0; const FullNameParser_1 = require("../parsers/FullNameParser"); /** * Parses a table name through the SQL parser so all supported identifier * syntaxes (quoted, bracketed, backtick) converge to a consistent key. */ const normalizeTableName = (tableName) => { var _a; // Parse with the same rules as the main AST to avoid regex-based drift. const parsed = FullNameParser_1.FullNameParser.parse(tableName); const namespaces = (_a = parsed.namespaces) !== null && _a !== void 0 ? _a : []; const parts = [...namespaces, parsed.name.name]; return parts.join('.').toLowerCase(); }; exports.normalizeTableName = normalizeTableName; /** * For schema-sensitive matching we no longer drop qualifiers; a single * normalized key is sufficient and safer than heuristic variants. */ const tableNameVariants = (tableName) => { var _a; const parsed = FullNameParser_1.FullNameParser.parse(tableName); const namespaces = (_a = parsed.namespaces) !== null && _a !== void 0 ? _a : []; const normalized = (0, exports.normalizeTableName)(tableName); // Return the parsed-normalized key alone when no schema qualifier is present. if (namespaces.length === 0) { return [normalized]; } // DONOT return an unqualified variant; schema-qualified normalization is required to avoid mixing distinct tables. return [normalized]; }; exports.tableNameVariants = tableNameVariants; //# sourceMappingURL=TableNameUtils.js.map