@mikro-orm/core 6.4.12-dev.1 → 6.4.12-dev.3

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.
@@ -165,6 +165,10 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
165
165
  * });
166
166
  * ```
167
167
  *
168
+ * The options also support an `includeCount` (true by default) option. If set to false, the `totalCount` is not
169
+ * returned as part of the cursor. This is useful for performance reason, when you don't care about the total number
170
+ * of pages.
171
+ *
168
172
  * The `Cursor` object provides the following interface:
169
173
  *
170
174
  * ```ts
@@ -174,7 +178,7 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
174
178
  * User { ... },
175
179
  * User { ... },
176
180
  * ],
177
- * totalCount: 50,
181
+ * totalCount: 50, // not included if `includeCount: false`
178
182
  * startCursor: 'WzRd',
179
183
  * endCursor: 'WzZd',
180
184
  * hasPrevPage: true,
@@ -182,7 +186,7 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
182
186
  * }
183
187
  * ```
184
188
  */
185
- findByCursor<Entity extends object, Hint extends string = never, Fields extends string = '*', Excludes extends string = never>(entityName: EntityName<Entity>, where: FilterQuery<NoInfer<Entity>>, options: FindByCursorOptions<Entity, Hint, Fields, Excludes>): Promise<Cursor<Entity, Hint, Fields, Excludes>>;
189
+ findByCursor<Entity extends object, Hint extends string = never, Fields extends string = '*', Excludes extends string = never, IncludeCount extends boolean = true>(entityName: EntityName<Entity>, where: FilterQuery<NoInfer<Entity>>, options: FindByCursorOptions<Entity, Hint, Fields, Excludes, IncludeCount>): Promise<Cursor<Entity, Hint, Fields, Excludes, IncludeCount>>;
186
190
  /**
187
191
  * Refreshes the persistent state of an entity from the database, overriding any local changes that have not yet been
188
192
  * persisted. Returns the same entity instance (same object reference), but re-hydrated. If the entity is no longer
package/EntityManager.js CHANGED
@@ -426,6 +426,10 @@ class EntityManager {
426
426
  * });
427
427
  * ```
428
428
  *
429
+ * The options also support an `includeCount` (true by default) option. If set to false, the `totalCount` is not
430
+ * returned as part of the cursor. This is useful for performance reason, when you don't care about the total number
431
+ * of pages.
432
+ *
429
433
  * The `Cursor` object provides the following interface:
430
434
  *
431
435
  * ```ts
@@ -435,7 +439,7 @@ class EntityManager {
435
439
  * User { ... },
436
440
  * User { ... },
437
441
  * ],
438
- * totalCount: 50,
442
+ * totalCount: 50, // not included if `includeCount: false`
439
443
  * startCursor: 'WzRd',
440
444
  * endCursor: 'WzZd',
441
445
  * hasPrevPage: true,
@@ -450,7 +454,9 @@ class EntityManager {
450
454
  if (utils_1.Utils.isEmpty(options.orderBy)) {
451
455
  throw new Error('Explicit `orderBy` option required');
452
456
  }
453
- const [entities, count] = await em.findAndCount(entityName, where, options);
457
+ const [entities, count] = options.includeCount !== false
458
+ ? await em.findAndCount(entityName, where, options)
459
+ : [await em.find(entityName, where, options)];
454
460
  return new utils_1.Cursor(entities, count, options, this.metadata.get(entityName));
455
461
  }
456
462
  /**
@@ -149,7 +149,8 @@ export interface FindOptions<Entity, Hint extends string = never, Fields extends
149
149
  /** @internal used to apply filters to the auto-joined relations */
150
150
  em?: EntityManager;
151
151
  }
152
- export interface FindByCursorOptions<T extends object, P extends string = never, F extends string = '*', E extends string = never> extends Omit<FindOptions<T, P, F, E>, 'limit' | 'offset'> {
152
+ export interface FindByCursorOptions<T extends object, P extends string = never, F extends string = '*', E extends string = never, I extends boolean = true> extends Omit<FindOptions<T, P, F, E>, 'limit' | 'offset'> {
153
+ includeCount?: I;
153
154
  }
154
155
  export interface FindOneOptions<T extends object, P extends string = never, F extends string = '*', E extends string = never> extends Omit<FindOptions<T, P, F, E>, 'limit' | 'lockMode'> {
155
156
  lockMode?: LockMode;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "6.4.12-dev.1",
3
+ "version": "6.4.12-dev.3",
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",
@@ -64,7 +64,7 @@
64
64
  "esprima": "4.0.1",
65
65
  "fs-extra": "11.3.0",
66
66
  "globby": "11.1.0",
67
- "mikro-orm": "6.4.12-dev.1",
67
+ "mikro-orm": "6.4.12-dev.3",
68
68
  "reflect-metadata": "0.2.2"
69
69
  }
70
70
  }
package/utils/Cursor.d.ts CHANGED
@@ -49,13 +49,13 @@ import { type QueryOrder } from '../enums';
49
49
  * }
50
50
  * ```
51
51
  */
52
- export declare class Cursor<Entity extends object, Hint extends string = never, Fields extends string = '*', Excludes extends string = never> {
52
+ export declare class Cursor<Entity extends object, Hint extends string = never, Fields extends string = '*', Excludes extends string = never, IncludeCount extends boolean = true> {
53
53
  readonly items: Loaded<Entity, Hint, Fields, Excludes>[];
54
- readonly totalCount: number;
54
+ readonly totalCount: IncludeCount extends true ? number : undefined;
55
55
  readonly hasPrevPage: boolean;
56
56
  readonly hasNextPage: boolean;
57
57
  private readonly definition;
58
- constructor(items: Loaded<Entity, Hint, Fields, Excludes>[], totalCount: number, options: FindByCursorOptions<Entity, Hint, Fields, Excludes>, meta: EntityMetadata<Entity>);
58
+ constructor(items: Loaded<Entity, Hint, Fields, Excludes>[], totalCount: IncludeCount extends true ? number : undefined, options: FindByCursorOptions<Entity, Hint, Fields, Excludes, IncludeCount>, meta: EntityMetadata<Entity>);
59
59
  get startCursor(): string | null;
60
60
  get endCursor(): string | null;
61
61
  /**