@mikro-orm/knex 6.0.0-dev.23 → 6.0.0-dev.24

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.
@@ -29,16 +29,25 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
29
29
  const qb = this.createQueryBuilder(entityName, options.ctx, options.connectionType, false);
30
30
  const fields = this.buildFields(meta, populate, joinedProps, qb, options.fields);
31
31
  const joinedPropsOrderBy = this.buildJoinedPropsOrderBy(entityName, qb, meta, joinedProps);
32
+ const orderBy = [...core_1.Utils.asArray(options.orderBy), ...joinedPropsOrderBy];
32
33
  if (core_1.Utils.isPrimaryKey(where, meta.compositePK)) {
33
34
  where = { [core_1.Utils.getPrimaryKeyHash(meta.primaryKeys)]: where };
34
35
  }
36
+ const { first, last, before, after } = options;
37
+ const isCursorPagination = [first, last, before, after].some(v => v != null);
35
38
  qb.select(fields)
36
39
  .populate(populate, joinedProps.length > 0 ? options.populateWhere : undefined)
37
40
  .where(where)
38
- .orderBy([...core_1.Utils.asArray(options.orderBy), ...joinedPropsOrderBy])
39
41
  .groupBy(options.groupBy)
40
42
  .having(options.having)
41
43
  .withSchema(this.getSchemaName(meta, options));
44
+ if (isCursorPagination) {
45
+ const { orderBy: newOrderBy, where } = this.processCursorOptions(meta, options, orderBy);
46
+ qb.andWhere(where).orderBy(newOrderBy);
47
+ }
48
+ else {
49
+ qb.orderBy(orderBy);
50
+ }
42
51
  if (options.limit !== undefined) {
43
52
  qb.limit(options.limit, options.offset);
44
53
  }
@@ -47,6 +56,9 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
47
56
  }
48
57
  core_1.Utils.asArray(options.flags).forEach(flag => qb.setFlag(flag));
49
58
  const result = await this.rethrow(qb.execute('all'));
59
+ if (isCursorPagination && !first && !!last) {
60
+ result.reverse();
61
+ }
50
62
  if (joinedProps.length > 0) {
51
63
  return this.mergeJoinedResult(result, meta);
52
64
  }
@@ -674,7 +686,11 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
674
686
  });
675
687
  /* istanbul ignore else */
676
688
  if (this.platform.allowsMultiInsert()) {
677
- await this.nativeInsertMany(prop.pivotEntity, items, { ...options, convertCustomTypes: false, processCollections: false });
689
+ await this.nativeInsertMany(prop.pivotEntity, items, {
690
+ ...options,
691
+ convertCustomTypes: false,
692
+ processCollections: false,
693
+ });
678
694
  }
679
695
  else {
680
696
  await core_1.Utils.runSerial(items, item => {
package/index.mjs CHANGED
@@ -36,6 +36,7 @@ export const ConnectionException = mod.ConnectionException;
36
36
  export const ConstraintViolationException = mod.ConstraintViolationException;
37
37
  export const CriteriaNode = mod.CriteriaNode;
38
38
  export const CriteriaNodeFactory = mod.CriteriaNodeFactory;
39
+ export const Cursor = mod.Cursor;
39
40
  export const DatabaseDriver = mod.DatabaseDriver;
40
41
  export const DatabaseObjectExistsException = mod.DatabaseObjectExistsException;
41
42
  export const DatabaseObjectNotFoundException = mod.DatabaseObjectNotFoundException;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/knex",
3
- "version": "6.0.0-dev.23",
3
+ "version": "6.0.0-dev.24",
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,6 +66,6 @@
66
66
  "@mikro-orm/core": "^5.6.8"
67
67
  },
68
68
  "peerDependencies": {
69
- "@mikro-orm/core": "~6.0.0-dev.23"
69
+ "@mikro-orm/core": "~6.0.0-dev.24"
70
70
  }
71
71
  }