@query-doctor/core 0.2.3 → 0.2.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.js CHANGED
@@ -1172,7 +1172,31 @@ var _IndexOptimizer = class _IndexOptimizer {
1172
1172
  // TODO: this doesn't belong in the optimizer
1173
1173
  indexAlreadyExists(table, columns) {
1174
1174
  return this.existingIndexes.find(
1175
- (index) => index.index_type === "btree" && index.table_name === table && index.index_columns.length === columns.length && index.index_columns.every((c, i) => columns[i].column === c.name)
1175
+ (index) => index.index_type === "btree" && index.table_name === table && index.index_columns.length === columns.length && index.index_columns.every((c, i) => {
1176
+ if (columns[i].column !== c.name) {
1177
+ return false;
1178
+ }
1179
+ if (columns[i].where) {
1180
+ return false;
1181
+ }
1182
+ if (columns[i].sort) {
1183
+ switch (columns[i].sort.dir) {
1184
+ // Sorting is ASC by default in postgres
1185
+ case "SORTBY_DEFAULT":
1186
+ case "SORTBY_ASC":
1187
+ if (c.order !== "ASC") {
1188
+ return false;
1189
+ }
1190
+ break;
1191
+ case "SORTBY_DESC":
1192
+ if (c.order !== "DESC") {
1193
+ return false;
1194
+ }
1195
+ break;
1196
+ }
1197
+ }
1198
+ return true;
1199
+ })
1176
1200
  );
1177
1201
  }
1178
1202
  /**