@query-doctor/core 0.1.0 → 0.1.1

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 CHANGED
@@ -318,11 +318,15 @@ var Walker = class _Walker {
318
318
  }
319
319
  }
320
320
  if (is2(node, "RangeVar") && node.RangeVar.relname) {
321
- this.tableMappings.set(node.RangeVar.relname, {
321
+ const columnReference = {
322
322
  text: node.RangeVar.relname,
323
323
  start: node.RangeVar.location,
324
324
  quoted: false
325
- });
325
+ };
326
+ if (node.RangeVar.schemaname) {
327
+ columnReference.schema = node.RangeVar.schemaname;
328
+ }
329
+ this.tableMappings.set(node.RangeVar.relname, columnReference);
326
330
  if (node.RangeVar.alias?.aliasname) {
327
331
  const aliasName = node.RangeVar.alias.aliasname;
328
332
  const existingMapping = this.tableMappings.get(aliasName);
@@ -335,9 +339,12 @@ var Walker = class _Walker {
335
339
  quoted: true,
336
340
  alias: aliasName
337
341
  };
342
+ if (node.RangeVar.schemaname) {
343
+ part.schema = node.RangeVar.schemaname;
344
+ }
338
345
  if (existingMapping) {
339
346
  console.warn(
340
- `Ignoring alias ${aliasName} as it shadows an existing mapping. We currently do not support alias shadowing.`
347
+ `Ignoring alias ${aliasName} as it shadows an existing mapping for ${existingMapping.text}. We currently do not support alias shadowing.`
341
348
  );
342
349
  this.shadowedAliases.push(part);
343
350
  return;
@@ -573,7 +580,10 @@ var Analyzer = class {
573
580
  const referencedTables = [];
574
581
  for (const value of tableMappings.values()) {
575
582
  if (!value.alias) {
576
- referencedTables.push(value.text);
583
+ referencedTables.push({
584
+ schema: value.schema,
585
+ table: value.text
586
+ });
577
587
  }
578
588
  }
579
589
  const { tags, queryWithoutTags } = this.extractSqlcommenter(query);
@@ -629,13 +639,14 @@ var Analyzer = class {
629
639
  }
630
640
  } else if (tableReference) {
631
641
  const [table, column] = colReference.parts;
642
+ const referencedSchema = table.schema;
632
643
  const referencedTable = this.normalize(table);
633
644
  const referencedColumn = this.normalize(column);
634
645
  const matchingTable = tables.find((table2) => {
635
646
  const hasMatchingColumn = table2.columns?.some((column2) => {
636
647
  return column2.columnName === referencedColumn;
637
648
  }) ?? false;
638
- return table2.tableName === referencedTable && hasMatchingColumn;
649
+ return table2.schemaName === referencedSchema && table2.tableName === referencedTable && hasMatchingColumn;
639
650
  });
640
651
  if (matchingTable) {
641
652
  const index = {