@nocobase/database 1.4.0-alpha.20240902080620 → 1.4.0-alpha.20240903050434

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.
@@ -26,6 +26,11 @@ export declare abstract class RelationRepository {
26
26
  database: Database;
27
27
  constructor(sourceCollection: Collection, association: string, sourceKeyValue: string | number);
28
28
  get collection(): Collection<any, any>;
29
+ abstract find(options?: FindOptions): Promise<any>;
30
+ chunk(options: FindOptions & {
31
+ chunkSize: number;
32
+ callback: (rows: Model[], options: FindOptions) => Promise<void>;
33
+ }): Promise<void>;
29
34
  convertTk(options: any): any;
30
35
  convertTks(options: any): any[];
31
36
  targetKey(): any;
@@ -83,6 +83,30 @@ const _RelationRepository = class _RelationRepository {
83
83
  get collection() {
84
84
  return this.db.getCollection(this.targetModel.name);
85
85
  }
86
+ async chunk(options) {
87
+ const { chunkSize, callback, limit: overallLimit } = options;
88
+ const transaction2 = await this.getTransaction(options);
89
+ let offset = 0;
90
+ let totalProcessed = 0;
91
+ while (true) {
92
+ const currentLimit = overallLimit !== void 0 ? Math.min(chunkSize, overallLimit - totalProcessed) : chunkSize;
93
+ const rows = await this.find({
94
+ ...options,
95
+ limit: currentLimit,
96
+ offset,
97
+ transaction: transaction2
98
+ });
99
+ if (rows.length === 0) {
100
+ break;
101
+ }
102
+ await callback(rows, options);
103
+ offset += currentLimit;
104
+ totalProcessed += rows.length;
105
+ if (overallLimit !== void 0 && totalProcessed >= overallLimit) {
106
+ break;
107
+ }
108
+ }
109
+ }
86
110
  convertTk(options) {
87
111
  let tk = options;
88
112
  if (typeof options === "object" && options["tk"]) {
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@nocobase/database",
3
- "version": "1.4.0-alpha.20240902080620",
3
+ "version": "1.4.0-alpha.20240903050434",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",
7
7
  "license": "AGPL-3.0",
8
8
  "dependencies": {
9
- "@nocobase/logger": "1.4.0-alpha.20240902080620",
10
- "@nocobase/utils": "1.4.0-alpha.20240902080620",
9
+ "@nocobase/logger": "1.4.0-alpha.20240903050434",
10
+ "@nocobase/utils": "1.4.0-alpha.20240903050434",
11
11
  "async-mutex": "^0.3.2",
12
12
  "chalk": "^4.1.1",
13
13
  "cron-parser": "4.4.0",
@@ -38,5 +38,5 @@
38
38
  "url": "git+https://github.com/nocobase/nocobase.git",
39
39
  "directory": "packages/database"
40
40
  },
41
- "gitHead": "3185104153d9de90e3fbfbd46f677cad3f69f4ec"
41
+ "gitHead": "1f4364e7a0ce1998e570bfb94397525a947b959f"
42
42
  }