@mikro-orm/mongodb 7.1.0-dev.2 → 7.1.0-dev.4
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/MongoDriver.d.ts +1 -0
- package/MongoDriver.js +21 -0
- package/package.json +2 -2
package/MongoDriver.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ export declare class MongoDriver extends DatabaseDriver<MongoConnection> {
|
|
|
20
20
|
streamVirtual<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>, options: FindOptions<T, any, any, any>): AsyncIterableIterator<EntityData<T>>;
|
|
21
21
|
count<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>, options?: CountOptions<T>): Promise<number>;
|
|
22
22
|
nativeInsert<T extends object>(entityName: EntityName<T>, data: EntityDictionary<T>, options?: NativeInsertUpdateOptions<T>): Promise<QueryResult<T>>;
|
|
23
|
+
nativeClone<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>, overrides?: EntityData<T>, options?: NativeInsertUpdateOptions<T>): Promise<QueryResult<T>>;
|
|
23
24
|
nativeInsertMany<T extends object>(entityName: EntityName<T>, data: EntityDictionary<T>[], options?: NativeInsertUpdateManyOptions<T>): Promise<QueryResult<T>>;
|
|
24
25
|
nativeUpdate<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>, data: EntityDictionary<T>, options?: NativeInsertUpdateOptions<T> & UpsertOptions<T>): Promise<QueryResult<T>>;
|
|
25
26
|
nativeUpdateMany<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>[], data: EntityDictionary<T>[], options?: NativeInsertUpdateOptions<T> & UpsertManyOptions<T>): Promise<QueryResult<T>>;
|
package/MongoDriver.js
CHANGED
|
@@ -148,6 +148,27 @@ export class MongoDriver extends DatabaseDriver {
|
|
|
148
148
|
data = this.renameFields(entityName, data);
|
|
149
149
|
return this.rethrow(this.getConnection('write').insertOne(entityName, data, options.ctx));
|
|
150
150
|
}
|
|
151
|
+
async nativeClone(entityName, where, overrides, options = {}) {
|
|
152
|
+
const meta = this.metadata.find(entityName);
|
|
153
|
+
const pk = meta.getPrimaryProps()[0].fieldNames[0] ?? '_id';
|
|
154
|
+
const normalizedWhere = Utils.isPrimaryKey(where) ? { [pk]: where } : where;
|
|
155
|
+
const renameWhere = this.renameFields(entityName, normalizedWhere);
|
|
156
|
+
const source = await this.rethrow(this.getConnection('read').find(entityName, renameWhere, { ctx: options.ctx, limit: 1 }));
|
|
157
|
+
if (!source.length) {
|
|
158
|
+
throw new Error('Cannot clone: no entity found matching the given condition');
|
|
159
|
+
}
|
|
160
|
+
const doc = source[0];
|
|
161
|
+
delete doc[pk];
|
|
162
|
+
if (overrides) {
|
|
163
|
+
const mapped = this.renameFields(entityName, overrides);
|
|
164
|
+
Object.assign(doc, mapped);
|
|
165
|
+
}
|
|
166
|
+
if (meta.versionProperty) {
|
|
167
|
+
const vProp = meta.properties[meta.versionProperty];
|
|
168
|
+
doc[vProp.fieldNames[0]] = vProp.runtimeType === 'Date' ? new Date() : 1;
|
|
169
|
+
}
|
|
170
|
+
return this.rethrow(this.getConnection('write').insertOne(entityName, doc, options.ctx));
|
|
171
|
+
}
|
|
151
172
|
async nativeInsertMany(entityName, data, options = {}) {
|
|
152
173
|
data = data.map(item => {
|
|
153
174
|
this.handleVersionProperty(entityName, item);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/mongodb",
|
|
3
|
-
"version": "7.1.0-dev.
|
|
3
|
+
"version": "7.1.0-dev.4",
|
|
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
|
"keywords": [
|
|
6
6
|
"data-mapper",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"@mikro-orm/core": "^7.0.11"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@mikro-orm/core": "7.1.0-dev.
|
|
56
|
+
"@mikro-orm/core": "7.1.0-dev.4"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|
|
59
59
|
"node": ">= 22.17.0"
|