@query-doctor/core 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +29 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +29 -14
- package/dist/index.js.map +1 -1
- package/dist/sql/analyzer.d.ts +3 -1
- package/dist/sql/analyzer.d.ts.map +1 -1
- package/dist/sql/pg-identifier.d.ts +1 -0
- package/dist/sql/pg-identifier.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -550,7 +550,7 @@ var Analyzer = class {
|
|
|
550
550
|
nudges
|
|
551
551
|
};
|
|
552
552
|
}
|
|
553
|
-
deriveIndexes(tables, discovered) {
|
|
553
|
+
deriveIndexes(tables, discovered, referencedTables) {
|
|
554
554
|
const allIndexes = [];
|
|
555
555
|
const seenIndexes = /* @__PURE__ */ new Set();
|
|
556
556
|
function addIndex(index) {
|
|
@@ -561,6 +561,7 @@ var Analyzer = class {
|
|
|
561
561
|
seenIndexes.add(key);
|
|
562
562
|
allIndexes.push(index);
|
|
563
563
|
}
|
|
564
|
+
const matchingTables = this.filterReferences(referencedTables, tables);
|
|
564
565
|
for (const colReference of discovered) {
|
|
565
566
|
const partsCount = colReference.parts.length;
|
|
566
567
|
const columnOnlyReference = partsCount === 1;
|
|
@@ -569,12 +570,10 @@ var Analyzer = class {
|
|
|
569
570
|
if (columnOnlyReference) {
|
|
570
571
|
const [column] = colReference.parts;
|
|
571
572
|
const referencedColumn = this.normalize(column);
|
|
572
|
-
const matchingTables = tables.filter((table) => {
|
|
573
|
-
return table.columns?.some((column2) => {
|
|
574
|
-
return column2.columnName === referencedColumn;
|
|
575
|
-
}) ?? false;
|
|
576
|
-
});
|
|
577
573
|
for (const table of matchingTables) {
|
|
574
|
+
if (!this.hasColumn(table, referencedColumn)) {
|
|
575
|
+
continue;
|
|
576
|
+
}
|
|
578
577
|
const index = {
|
|
579
578
|
schema: table.schemaName,
|
|
580
579
|
table: table.tableName,
|
|
@@ -590,16 +589,12 @@ var Analyzer = class {
|
|
|
590
589
|
}
|
|
591
590
|
} else if (tableReference) {
|
|
592
591
|
const [table, column] = colReference.parts;
|
|
593
|
-
const referencedSchema = table.schema;
|
|
594
592
|
const referencedTable = this.normalize(table);
|
|
595
593
|
const referencedColumn = this.normalize(column);
|
|
596
|
-
const matchingTable
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
}
|
|
600
|
-
return table2.schemaName === referencedSchema && table2.tableName === referencedTable && hasMatchingColumn;
|
|
601
|
-
});
|
|
602
|
-
if (matchingTable) {
|
|
594
|
+
for (const matchingTable of matchingTables) {
|
|
595
|
+
if (!this.hasColumn(matchingTable, referencedColumn)) {
|
|
596
|
+
continue;
|
|
597
|
+
}
|
|
603
598
|
const index = {
|
|
604
599
|
schema: matchingTable.schemaName,
|
|
605
600
|
table: referencedTable,
|
|
@@ -640,6 +635,23 @@ var Analyzer = class {
|
|
|
640
635
|
}
|
|
641
636
|
return allIndexes;
|
|
642
637
|
}
|
|
638
|
+
filterReferences(referencedTables, tables) {
|
|
639
|
+
const matchingTables = [];
|
|
640
|
+
for (const referencedTable of referencedTables) {
|
|
641
|
+
const refs = tables.filter(({ tableName, schemaName }) => {
|
|
642
|
+
let schemaMatches = true;
|
|
643
|
+
if (referencedTable.schema) {
|
|
644
|
+
schemaMatches = schemaName === referencedTable.schema;
|
|
645
|
+
}
|
|
646
|
+
return schemaMatches && tableName === referencedTable.table;
|
|
647
|
+
});
|
|
648
|
+
matchingTables.push(...refs);
|
|
649
|
+
}
|
|
650
|
+
return matchingTables;
|
|
651
|
+
}
|
|
652
|
+
hasColumn(table, columnName) {
|
|
653
|
+
return table.columns?.some((column) => column.columnName === columnName) ?? false;
|
|
654
|
+
}
|
|
643
655
|
colorizeKeywords(query, color) {
|
|
644
656
|
return query.replace(
|
|
645
657
|
// eh? This kinda sucks
|
|
@@ -853,6 +865,9 @@ var _PgIdentifier = class _PgIdentifier {
|
|
|
853
865
|
}
|
|
854
866
|
return this.value;
|
|
855
867
|
}
|
|
868
|
+
toJSON() {
|
|
869
|
+
return this.toString();
|
|
870
|
+
}
|
|
856
871
|
};
|
|
857
872
|
// Every keyword that's not explicitly marked as
|
|
858
873
|
// unreserved in src/include/parser/kwlist.h
|