@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.js CHANGED
@@ -269,11 +269,15 @@ var Walker = class _Walker {
269
269
  }
270
270
  }
271
271
  if (is2(node, "RangeVar") && node.RangeVar.relname) {
272
- this.tableMappings.set(node.RangeVar.relname, {
272
+ const columnReference = {
273
273
  text: node.RangeVar.relname,
274
274
  start: node.RangeVar.location,
275
275
  quoted: false
276
- });
276
+ };
277
+ if (node.RangeVar.schemaname) {
278
+ columnReference.schema = node.RangeVar.schemaname;
279
+ }
280
+ this.tableMappings.set(node.RangeVar.relname, columnReference);
277
281
  if (node.RangeVar.alias?.aliasname) {
278
282
  const aliasName = node.RangeVar.alias.aliasname;
279
283
  const existingMapping = this.tableMappings.get(aliasName);
@@ -286,9 +290,12 @@ var Walker = class _Walker {
286
290
  quoted: true,
287
291
  alias: aliasName
288
292
  };
293
+ if (node.RangeVar.schemaname) {
294
+ part.schema = node.RangeVar.schemaname;
295
+ }
289
296
  if (existingMapping) {
290
297
  console.warn(
291
- `Ignoring alias ${aliasName} as it shadows an existing mapping. We currently do not support alias shadowing.`
298
+ `Ignoring alias ${aliasName} as it shadows an existing mapping for ${existingMapping.text}. We currently do not support alias shadowing.`
292
299
  );
293
300
  this.shadowedAliases.push(part);
294
301
  return;
@@ -524,7 +531,10 @@ var Analyzer = class {
524
531
  const referencedTables = [];
525
532
  for (const value of tableMappings.values()) {
526
533
  if (!value.alias) {
527
- referencedTables.push(value.text);
534
+ referencedTables.push({
535
+ schema: value.schema,
536
+ table: value.text
537
+ });
528
538
  }
529
539
  }
530
540
  const { tags, queryWithoutTags } = this.extractSqlcommenter(query);
@@ -580,13 +590,14 @@ var Analyzer = class {
580
590
  }
581
591
  } else if (tableReference) {
582
592
  const [table, column] = colReference.parts;
593
+ const referencedSchema = table.schema;
583
594
  const referencedTable = this.normalize(table);
584
595
  const referencedColumn = this.normalize(column);
585
596
  const matchingTable = tables.find((table2) => {
586
597
  const hasMatchingColumn = table2.columns?.some((column2) => {
587
598
  return column2.columnName === referencedColumn;
588
599
  }) ?? false;
589
- return table2.tableName === referencedTable && hasMatchingColumn;
600
+ return table2.schemaName === referencedSchema && table2.tableName === referencedTable && hasMatchingColumn;
590
601
  });
591
602
  if (matchingTable) {
592
603
  const index = {