@mikro-orm/knex 6.3.5-dev.10 → 6.3.5-dev.12

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.
@@ -135,11 +135,19 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
135
135
  .indexHint(options.indexHint)
136
136
  .comment(options.comments)
137
137
  .hintComment(options.hintComments);
138
+ const { first, last, before, after } = options;
139
+ const isCursorPagination = [first, last, before, after].some(v => v != null);
138
140
  if (type !== query_1.QueryType.COUNT) {
139
- qb.limit(options?.limit, options?.offset);
140
141
  if (options.orderBy) {
141
- qb.orderBy(options.orderBy);
142
+ if (isCursorPagination) {
143
+ const { orderBy: newOrderBy, where } = this.processCursorOptions(meta, options, options.orderBy);
144
+ qb.andWhere(where).orderBy(newOrderBy);
145
+ }
146
+ else {
147
+ qb.orderBy(options.orderBy);
148
+ }
142
149
  }
150
+ qb.limit(options?.limit, options?.offset);
143
151
  }
144
152
  qb.where(where);
145
153
  const kqb = qb.getKnexQuery(false).clear('select');
@@ -154,6 +162,9 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
154
162
  if (type === query_1.QueryType.COUNT) {
155
163
  return res[0].count;
156
164
  }
165
+ if (isCursorPagination && !first && !!last) {
166
+ res.reverse();
167
+ }
157
168
  return res.map(row => this.mapResult(row, meta));
158
169
  }
159
170
  mapResult(result, meta, populate = [], qb, map = {}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/knex",
3
- "version": "6.3.5-dev.10",
3
+ "version": "6.3.5-dev.12",
4
4
  "description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
5
5
  "main": "index.js",
6
6
  "module": "index.mjs",
@@ -66,7 +66,7 @@
66
66
  "@mikro-orm/core": "^6.3.4"
67
67
  },
68
68
  "peerDependencies": {
69
- "@mikro-orm/core": "6.3.5-dev.10",
69
+ "@mikro-orm/core": "6.3.5-dev.12",
70
70
  "better-sqlite3": "*",
71
71
  "libsql": "*",
72
72
  "mariadb": "*"
@@ -421,12 +421,9 @@ class DatabaseTable {
421
421
  findFkIndex(currentFk) {
422
422
  const fkColumnsLength = currentFk.columnNames.length;
423
423
  const possibleIndexes = this.indexes.filter(index => {
424
- return index.columnNames.length >= fkColumnsLength && !currentFk.columnNames.some((columnName, i) => index.columnNames[i] !== columnName);
424
+ return index.columnNames.length === fkColumnsLength && !currentFk.columnNames.some((columnName, i) => index.columnNames[i] !== columnName);
425
425
  });
426
426
  possibleIndexes.sort((a, b) => {
427
- if (a.columnNames.length !== b.columnNames.length) {
428
- return a.columnNames.length < b.columnNames.length ? -1 : 1;
429
- }
430
427
  if (a.primary !== b.primary) {
431
428
  return a.primary ? -1 : 1;
432
429
  }