@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.cjs
CHANGED
|
@@ -600,7 +600,7 @@ var Analyzer = class {
|
|
|
600
600
|
nudges
|
|
601
601
|
};
|
|
602
602
|
}
|
|
603
|
-
deriveIndexes(tables, discovered) {
|
|
603
|
+
deriveIndexes(tables, discovered, referencedTables) {
|
|
604
604
|
const allIndexes = [];
|
|
605
605
|
const seenIndexes = /* @__PURE__ */ new Set();
|
|
606
606
|
function addIndex(index) {
|
|
@@ -611,6 +611,7 @@ var Analyzer = class {
|
|
|
611
611
|
seenIndexes.add(key);
|
|
612
612
|
allIndexes.push(index);
|
|
613
613
|
}
|
|
614
|
+
const matchingTables = this.filterReferences(referencedTables, tables);
|
|
614
615
|
for (const colReference of discovered) {
|
|
615
616
|
const partsCount = colReference.parts.length;
|
|
616
617
|
const columnOnlyReference = partsCount === 1;
|
|
@@ -619,12 +620,10 @@ var Analyzer = class {
|
|
|
619
620
|
if (columnOnlyReference) {
|
|
620
621
|
const [column] = colReference.parts;
|
|
621
622
|
const referencedColumn = this.normalize(column);
|
|
622
|
-
const matchingTables = tables.filter((table) => {
|
|
623
|
-
return table.columns?.some((column2) => {
|
|
624
|
-
return column2.columnName === referencedColumn;
|
|
625
|
-
}) ?? false;
|
|
626
|
-
});
|
|
627
623
|
for (const table of matchingTables) {
|
|
624
|
+
if (!this.hasColumn(table, referencedColumn)) {
|
|
625
|
+
continue;
|
|
626
|
+
}
|
|
628
627
|
const index = {
|
|
629
628
|
schema: table.schemaName,
|
|
630
629
|
table: table.tableName,
|
|
@@ -640,16 +639,12 @@ var Analyzer = class {
|
|
|
640
639
|
}
|
|
641
640
|
} else if (tableReference) {
|
|
642
641
|
const [table, column] = colReference.parts;
|
|
643
|
-
const referencedSchema = table.schema;
|
|
644
642
|
const referencedTable = this.normalize(table);
|
|
645
643
|
const referencedColumn = this.normalize(column);
|
|
646
|
-
const matchingTable
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
}
|
|
650
|
-
return table2.schemaName === referencedSchema && table2.tableName === referencedTable && hasMatchingColumn;
|
|
651
|
-
});
|
|
652
|
-
if (matchingTable) {
|
|
644
|
+
for (const matchingTable of matchingTables) {
|
|
645
|
+
if (!this.hasColumn(matchingTable, referencedColumn)) {
|
|
646
|
+
continue;
|
|
647
|
+
}
|
|
653
648
|
const index = {
|
|
654
649
|
schema: matchingTable.schemaName,
|
|
655
650
|
table: referencedTable,
|
|
@@ -690,6 +685,23 @@ var Analyzer = class {
|
|
|
690
685
|
}
|
|
691
686
|
return allIndexes;
|
|
692
687
|
}
|
|
688
|
+
filterReferences(referencedTables, tables) {
|
|
689
|
+
const matchingTables = [];
|
|
690
|
+
for (const referencedTable of referencedTables) {
|
|
691
|
+
const refs = tables.filter(({ tableName, schemaName }) => {
|
|
692
|
+
let schemaMatches = true;
|
|
693
|
+
if (referencedTable.schema) {
|
|
694
|
+
schemaMatches = schemaName === referencedTable.schema;
|
|
695
|
+
}
|
|
696
|
+
return schemaMatches && tableName === referencedTable.table;
|
|
697
|
+
});
|
|
698
|
+
matchingTables.push(...refs);
|
|
699
|
+
}
|
|
700
|
+
return matchingTables;
|
|
701
|
+
}
|
|
702
|
+
hasColumn(table, columnName) {
|
|
703
|
+
return table.columns?.some((column) => column.columnName === columnName) ?? false;
|
|
704
|
+
}
|
|
693
705
|
colorizeKeywords(query, color) {
|
|
694
706
|
return query.replace(
|
|
695
707
|
// eh? This kinda sucks
|
|
@@ -903,6 +915,9 @@ var _PgIdentifier = class _PgIdentifier {
|
|
|
903
915
|
}
|
|
904
916
|
return this.value;
|
|
905
917
|
}
|
|
918
|
+
toJSON() {
|
|
919
|
+
return this.toString();
|
|
920
|
+
}
|
|
906
921
|
};
|
|
907
922
|
// Every keyword that's not explicitly marked as
|
|
908
923
|
// unreserved in src/include/parser/kwlist.h
|