@query-doctor/core 0.1.11 → 0.2.0

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
@@ -1170,26 +1170,31 @@ var _IndexOptimizer = class _IndexOptimizer {
1170
1170
  indexesToCreate(rootCandidates) {
1171
1171
  const permutedIndexes = this.tableColumnIndexCandidates(rootCandidates);
1172
1172
  const nextStage = [];
1173
- for (const { table, schema, columns } of permutedIndexes.values()) {
1173
+ for (const permutation of permutedIndexes.values()) {
1174
+ const { table: rawTable, schema: rawSchema, columns } = permutation;
1174
1175
  const permutations = permuteWithFeedback(columns);
1175
1176
  let iter = permutations.next(PROCEED);
1176
1177
  while (!iter.done) {
1177
1178
  const columns2 = iter.value;
1178
- const existingIndex = this.indexAlreadyExists(table, columns2);
1179
+ const schema = PgIdentifier.fromString(rawSchema);
1180
+ const table = PgIdentifier.fromString(rawTable);
1181
+ const existingIndex = this.indexAlreadyExists(
1182
+ table.toString(),
1183
+ columns2
1184
+ );
1179
1185
  if (existingIndex) {
1180
1186
  iter = permutations.next(PROCEED);
1181
1187
  continue;
1182
1188
  }
1183
1189
  const indexName = this.indexName();
1184
- const shortenedSchema = schema === "public" ? "" : `"${schema}".`;
1185
- const indexDefinitionClean = `${shortenedSchema}"${table}"(${columns2.map((c) => `"${c.column}"`).join(", ")})`;
1190
+ const definition = this.toDefinition(permutation).raw;
1186
1191
  iter = permutations.next(PROCEED);
1187
1192
  nextStage.push({
1188
1193
  name: indexName,
1189
- schema,
1190
- table,
1194
+ schema: schema.toString(),
1195
+ table: table.toString(),
1191
1196
  columns: columns2,
1192
- definition: indexDefinitionClean
1197
+ definition
1193
1198
  });
1194
1199
  }
1195
1200
  }
@@ -1197,10 +1202,20 @@ var _IndexOptimizer = class _IndexOptimizer {
1197
1202
  }
1198
1203
  toDefinition(permuted) {
1199
1204
  const make = (col, order, where, keyword) => {
1200
- const baseColumn = `"${permuted.schema}"."${permuted.table}"(${permuted.columns.map((c) => {
1205
+ let fullyQualifiedTable;
1206
+ if (permuted.schema.toString() === "public") {
1207
+ fullyQualifiedTable = PgIdentifier.fromString(permuted.table);
1208
+ } else {
1209
+ fullyQualifiedTable = PgIdentifier.fromParts(
1210
+ permuted.schema,
1211
+ permuted.table
1212
+ );
1213
+ }
1214
+ const baseColumn = `${fullyQualifiedTable}(${permuted.columns.map((c) => {
1215
+ const column = PgIdentifier.fromString(c.column);
1201
1216
  const direction = c.sort && this.sortDirection(c.sort);
1202
1217
  const nulls = c.sort && this.nullsOrder(c.sort);
1203
- let sort = col(`"${c.column}"`);
1218
+ let sort = col(column.toString());
1204
1219
  if (direction) {
1205
1220
  sort += ` ${order(direction)}`;
1206
1221
  }