@nocobase/database 1.7.0-beta.8 → 1.7.0
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/lib/belongs-to-array/belongs-to-array-repository.d.ts +2 -2
- package/lib/belongs-to-array/belongs-to-array-repository.js +6 -7
- package/lib/cursor-builder.d.ts +38 -0
- package/lib/cursor-builder.js +307 -0
- package/lib/dialects/mariadb-dialect.d.ts +2 -0
- package/lib/dialects/mariadb-dialect.js +4 -0
- package/lib/eager-loading/eager-loading-tree.js +20 -10
- package/lib/fields/array-field.d.ts +1 -1
- package/lib/fields/array-field.js +12 -7
- package/lib/fields/date-field.js +14 -9
- package/lib/fields/datetime-no-tz-field.d.ts +1 -1
- package/lib/fields/datetime-no-tz-field.js +24 -18
- package/lib/fields/encryption-field/encryption-field.js +2 -0
- package/lib/fields/nanoid-field.js +12 -5
- package/lib/fields/set-field.d.ts +1 -1
- package/lib/fields/set-field.js +9 -4
- package/lib/fields/string-field.d.ts +4 -0
- package/lib/fields/string-field.js +18 -0
- package/lib/fields/text-field.d.ts +4 -0
- package/lib/fields/text-field.js +18 -0
- package/lib/fields/uuid-field.js +11 -4
- package/lib/index.d.ts +1 -0
- package/lib/index.js +3 -1
- package/lib/interfaces/index.d.ts +1 -0
- package/lib/interfaces/index.js +3 -1
- package/lib/interfaces/input-interface.d.ts +13 -0
- package/lib/interfaces/input-interface.js +64 -0
- package/lib/interfaces/time-interface.d.ts +13 -0
- package/lib/interfaces/time-interface.js +65 -0
- package/lib/interfaces/utils.js +4 -1
- package/lib/options-parser.d.ts +3 -1
- package/lib/options-parser.js +3 -2
- package/lib/query-interface/mysql-query-interface.d.ts +1 -0
- package/lib/query-interface/mysql-query-interface.js +3 -0
- package/lib/query-interface/postgres-query-interface.d.ts +1 -0
- package/lib/query-interface/postgres-query-interface.js +3 -0
- package/lib/query-interface/query-interface.d.ts +1 -0
- package/lib/query-interface/query-interface.js +4 -0
- package/lib/query-interface/sqlite-query-interface.d.ts +1 -0
- package/lib/query-interface/sqlite-query-interface.js +3 -0
- package/lib/relation-repository/hasmany-repository.js +7 -1
- package/lib/relation-repository/multiple-relation-repository.d.ts +4 -1
- package/lib/relation-repository/multiple-relation-repository.js +2 -2
- package/lib/repository.d.ts +21 -0
- package/lib/repository.js +30 -4
- package/lib/view-collection.js +1 -1
- package/package.json +6 -6
package/lib/repository.js
CHANGED
|
@@ -70,6 +70,8 @@ var import_hasone_repository = require("./relation-repository/hasone-repository"
|
|
|
70
70
|
var import_update_associations = require("./update-associations");
|
|
71
71
|
var import_update_guard = require("./update-guard");
|
|
72
72
|
var import_filter_utils = require("./utils/filter-utils");
|
|
73
|
+
var import_lodash2 = __toESM(require("lodash"));
|
|
74
|
+
var import_cursor_builder = require("./cursor-builder");
|
|
73
75
|
var import_sequelize2 = require("sequelize");
|
|
74
76
|
const debug = require("debug")("noco-database");
|
|
75
77
|
const transaction = (0, import_transaction_decorator.transactionWrapperBuilder)(function() {
|
|
@@ -121,10 +123,12 @@ const _Repository = class _Repository {
|
|
|
121
123
|
database;
|
|
122
124
|
collection;
|
|
123
125
|
model;
|
|
126
|
+
cursorBuilder;
|
|
124
127
|
constructor(collection) {
|
|
125
128
|
this.database = collection.context.database;
|
|
126
129
|
this.collection = collection;
|
|
127
130
|
this.model = collection.model;
|
|
131
|
+
this.cursorBuilder = new import_cursor_builder.SmartCursorBuilder(this.database.sequelize, this.model.tableName, this.collection);
|
|
128
132
|
}
|
|
129
133
|
/**
|
|
130
134
|
* return count by filter
|
|
@@ -205,18 +209,25 @@ const _Repository = class _Repository {
|
|
|
205
209
|
return await this.model.aggregate(field, method, queryOptions);
|
|
206
210
|
}
|
|
207
211
|
async chunk(options) {
|
|
208
|
-
const { chunkSize, callback, limit: overallLimit } = options;
|
|
212
|
+
const { chunkSize, callback, limit: overallLimit, beforeFind, afterFind } = options;
|
|
209
213
|
const transaction2 = await this.getTransaction(options);
|
|
210
214
|
let offset = 0;
|
|
211
215
|
let totalProcessed = 0;
|
|
212
216
|
while (true) {
|
|
213
217
|
const currentLimit = overallLimit !== void 0 ? Math.min(chunkSize, overallLimit - totalProcessed) : chunkSize;
|
|
214
|
-
const
|
|
218
|
+
const findOptions = {
|
|
215
219
|
...options,
|
|
216
220
|
limit: currentLimit,
|
|
217
221
|
offset,
|
|
218
222
|
transaction: transaction2
|
|
219
|
-
}
|
|
223
|
+
};
|
|
224
|
+
if (beforeFind) {
|
|
225
|
+
await beforeFind(findOptions);
|
|
226
|
+
}
|
|
227
|
+
const rows = await this.find(findOptions);
|
|
228
|
+
if (afterFind) {
|
|
229
|
+
await afterFind(rows, { ...findOptions, offset });
|
|
230
|
+
}
|
|
220
231
|
if (rows.length === 0) {
|
|
221
232
|
break;
|
|
222
233
|
}
|
|
@@ -228,6 +239,21 @@ const _Repository = class _Repository {
|
|
|
228
239
|
}
|
|
229
240
|
}
|
|
230
241
|
}
|
|
242
|
+
/**
|
|
243
|
+
* Cursor-based pagination query function.
|
|
244
|
+
* Ideal for large datasets (e.g., millions of rows)
|
|
245
|
+
* Note:
|
|
246
|
+
* 1. does not support jumping to arbitrary pages (e.g., "Page 5")
|
|
247
|
+
* 2. Requires a stable, indexed sort field (e.g. ID, createdAt)
|
|
248
|
+
* 3. If custom orderBy is used, it must match the cursor field(s) and direction, otherwise results may be incorrect or unstable.
|
|
249
|
+
* @param options
|
|
250
|
+
*/
|
|
251
|
+
async chunkWithCursor(options) {
|
|
252
|
+
return await this.cursorBuilder.chunk({
|
|
253
|
+
...options,
|
|
254
|
+
find: this.find.bind(this)
|
|
255
|
+
});
|
|
256
|
+
}
|
|
231
257
|
/**
|
|
232
258
|
* find
|
|
233
259
|
* @param options
|
|
@@ -535,7 +561,7 @@ const _Repository = class _Repository {
|
|
|
535
561
|
const parser = new import_options_parser.OptionsParser(options, {
|
|
536
562
|
collection: this.collection
|
|
537
563
|
});
|
|
538
|
-
const params = parser.toSequelizeParams();
|
|
564
|
+
const params = parser.toSequelizeParams({ parseSort: import_lodash2.default.isBoolean(options == null ? void 0 : options.parseSort) ? options.parseSort : true });
|
|
539
565
|
debug("sequelize query params %o", params);
|
|
540
566
|
if (options.where && params.where) {
|
|
541
567
|
params.where = {
|
package/lib/view-collection.js
CHANGED
|
@@ -44,7 +44,7 @@ const _ViewCollection = class _ViewCollection extends import_collection.Collecti
|
|
|
44
44
|
if (this.options.writableView) {
|
|
45
45
|
return [];
|
|
46
46
|
}
|
|
47
|
-
return ["create", "update", "destroy"];
|
|
47
|
+
return ["create", "update", "destroy", "importXlsx", "destroyMany", "updateMany"];
|
|
48
48
|
}
|
|
49
49
|
sequelizeModelOptions() {
|
|
50
50
|
const modelOptions = super.sequelizeModelOptions();
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/database",
|
|
3
|
-
"version": "1.7.0
|
|
3
|
+
"version": "1.7.0",
|
|
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.7.0
|
|
10
|
-
"@nocobase/utils": "1.7.0
|
|
9
|
+
"@nocobase/logger": "1.7.0",
|
|
10
|
+
"@nocobase/utils": "1.7.0",
|
|
11
11
|
"async-mutex": "^0.3.2",
|
|
12
12
|
"chalk": "^4.1.1",
|
|
13
13
|
"cron-parser": "4.4.0",
|
|
@@ -20,12 +20,12 @@
|
|
|
20
20
|
"graphlib": "^2.1.8",
|
|
21
21
|
"lodash": "^4.17.21",
|
|
22
22
|
"mathjs": "^10.6.1",
|
|
23
|
-
"nanoid": "^3.3.
|
|
23
|
+
"nanoid": "^3.3.11",
|
|
24
24
|
"node-fetch": "^2.6.7",
|
|
25
25
|
"node-sql-parser": "^4.18.0",
|
|
26
26
|
"qs": "^6.11.2",
|
|
27
27
|
"safe-json-stringify": "^1.2.0",
|
|
28
|
-
"semver": "^7.
|
|
28
|
+
"semver": "^7.7.1",
|
|
29
29
|
"sequelize": "^6.26.0",
|
|
30
30
|
"umzug": "^3.1.1",
|
|
31
31
|
"uuid": "^9.0.1"
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"url": "git+https://github.com/nocobase/nocobase.git",
|
|
39
39
|
"directory": "packages/database"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "767ae089e404a104d718962272289c0bec01803a"
|
|
42
42
|
}
|