@statezero/core 0.1.96 → 0.1.97
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.
|
@@ -120,12 +120,12 @@ export class Manager {
|
|
|
120
120
|
*/
|
|
121
121
|
create(data: any): Promise<any>;
|
|
122
122
|
/**
|
|
123
|
-
* Creates multiple model instances using the provided
|
|
123
|
+
* Creates multiple model instances using the provided model instances.
|
|
124
124
|
*
|
|
125
|
-
* @param {Array<
|
|
125
|
+
* @param {Array<Model>} modelInstances - Array of unsaved model instances to create.
|
|
126
126
|
* @returns {Promise<Array<*>>} A promise that resolves to an array of newly created model instances.
|
|
127
127
|
*/
|
|
128
|
-
bulkCreate(
|
|
128
|
+
bulkCreate(modelInstances: Array<Model>): Promise<Array<any>>;
|
|
129
129
|
/**
|
|
130
130
|
* Fetches all records using the current QuerySet.
|
|
131
131
|
*
|
|
@@ -153,13 +153,13 @@ export class Manager {
|
|
|
153
153
|
return this.newQuerySet().create(data);
|
|
154
154
|
}
|
|
155
155
|
/**
|
|
156
|
-
* Creates multiple model instances using the provided
|
|
156
|
+
* Creates multiple model instances using the provided model instances.
|
|
157
157
|
*
|
|
158
|
-
* @param {Array<
|
|
158
|
+
* @param {Array<Model>} modelInstances - Array of unsaved model instances to create.
|
|
159
159
|
* @returns {Promise<Array<*>>} A promise that resolves to an array of newly created model instances.
|
|
160
160
|
*/
|
|
161
|
-
async bulkCreate(
|
|
162
|
-
return this.newQuerySet().bulkCreate(
|
|
161
|
+
async bulkCreate(modelInstances) {
|
|
162
|
+
return this.newQuerySet().bulkCreate(modelInstances);
|
|
163
163
|
}
|
|
164
164
|
/**
|
|
165
165
|
* Fetches all records using the current QuerySet.
|
|
@@ -195,12 +195,12 @@ export class QuerySet<T> {
|
|
|
195
195
|
*/
|
|
196
196
|
create(data: Object): Promise<any>;
|
|
197
197
|
/**
|
|
198
|
-
* Creates multiple model instances using the provided
|
|
198
|
+
* Creates multiple model instances using the provided model instances.
|
|
199
199
|
*
|
|
200
|
-
* @param {Array<
|
|
200
|
+
* @param {Array<Model>} modelInstances - Array of unsaved model instances to create.
|
|
201
201
|
* @returns {Promise<Array<any>>} A promise that resolves to an array of newly created model instances.
|
|
202
202
|
*/
|
|
203
|
-
bulkCreate(
|
|
203
|
+
bulkCreate(modelInstances: Array<Model>): Promise<Array<any>>;
|
|
204
204
|
/**
|
|
205
205
|
* Updates records in the QuerySet.
|
|
206
206
|
*
|
|
@@ -268,3 +268,4 @@ export class QuerySet<T> {
|
|
|
268
268
|
[Symbol.asyncIterator](): AsyncIterator<T>;
|
|
269
269
|
}
|
|
270
270
|
import { ModelSerializer } from "./serializers.js";
|
|
271
|
+
import { Model } from "./model.js";
|
|
@@ -426,18 +426,23 @@ export class QuerySet {
|
|
|
426
426
|
return QueryExecutor.execute(newQs, "create", { data: serializedData });
|
|
427
427
|
}
|
|
428
428
|
/**
|
|
429
|
-
* Creates multiple model instances using the provided
|
|
429
|
+
* Creates multiple model instances using the provided model instances.
|
|
430
430
|
*
|
|
431
|
-
* @param {Array<
|
|
431
|
+
* @param {Array<Model>} modelInstances - Array of unsaved model instances to create.
|
|
432
432
|
* @returns {Promise<Array<any>>} A promise that resolves to an array of newly created model instances.
|
|
433
433
|
*/
|
|
434
|
-
async bulkCreate(
|
|
434
|
+
async bulkCreate(modelInstances) {
|
|
435
435
|
this.ensureNotMaterialized();
|
|
436
|
-
if (!Array.isArray(
|
|
437
|
-
throw new Error("bulkCreate expects an array of
|
|
436
|
+
if (!Array.isArray(modelInstances)) {
|
|
437
|
+
throw new Error("bulkCreate expects an array of model instances");
|
|
438
438
|
}
|
|
439
|
-
// Serialize each
|
|
440
|
-
const serializedDataList =
|
|
439
|
+
// Serialize each model instance using model.serialize()
|
|
440
|
+
const serializedDataList = modelInstances.map(instance => {
|
|
441
|
+
if (!instance || typeof instance.serialize !== 'function') {
|
|
442
|
+
throw new Error("bulkCreate requires model instances. Did you pass a plain object instead?");
|
|
443
|
+
}
|
|
444
|
+
return instance.serialize();
|
|
445
|
+
});
|
|
441
446
|
// Materialize for bulk create
|
|
442
447
|
const newQs = new QuerySet(this.ModelClass, {
|
|
443
448
|
...this._getConfig(),
|
package/package.json
CHANGED