(
entityName: EntityName<T>,
where: FilterQuery<T>,
overrides?: EntityData<T>,
options: NativeInsertUpdateOptions<T> = {},
)
| 332 | } |
| 333 | |
| 334 | override async nativeClone<T extends object>( |
| 335 | entityName: EntityName<T>, |
| 336 | where: FilterQuery<T>, |
| 337 | overrides?: EntityData<T>, |
| 338 | options: NativeInsertUpdateOptions<T> = {}, |
| 339 | ): Promise<QueryResult<T>> { |
| 340 | const meta = this.metadata.find(entityName)!; |
| 341 | const pk = meta.getPrimaryProps()[0].fieldNames[0] ?? '_id'; |
| 342 | const normalizedWhere = Utils.isPrimaryKey(where) ? ({ [pk]: where } as FilterQuery<T>) : where; |
| 343 | const renameWhere = this.renameFields(entityName, normalizedWhere as unknown as EntityDictionary<T>); |
| 344 | const source = await this.rethrow( |
| 345 | this.getConnection('read').find<T>(entityName, renameWhere as FilterQuery<T>, { ctx: options.ctx, limit: 1 }), |
| 346 | ); |
| 347 | |
| 348 | if (!source.length) { |
| 349 | throw new Error('Cannot clone: no entity found matching the given condition'); |
| 350 | } |
| 351 | |
| 352 | const doc = source[0] as Dictionary; |
| 353 | delete doc[pk]; |
| 354 | |
| 355 | if (overrides) { |
| 356 | const mapped = this.renameFields(entityName, overrides as unknown as EntityDictionary<T>); |
| 357 | Object.assign(doc, mapped); |
| 358 | } |
| 359 | |
| 360 | if (meta.versionProperty) { |
| 361 | const vProp = meta.properties[meta.versionProperty]; |
| 362 | doc[vProp.fieldNames[0]] = vProp.runtimeType === 'Date' ? new Date() : 1; |
| 363 | } |
| 364 | |
| 365 | return this.rethrow( |
| 366 | this.getConnection('write').insertOne<T>(entityName, doc as EntityDictionary<T>, options.ctx), |
| 367 | ) as unknown as Promise<QueryResult<T>>; |
| 368 | } |
| 369 | |
| 370 | async nativeInsertMany<T extends object>( |
| 371 | entityName: EntityName<T>, |
nothing calls this directly
no test coverage detected