(
entityName: EntityName<T>,
where: FilterQuery<T>[],
data: EntityDictionary<T>[],
options: NativeInsertUpdateOptions<T> & UpsertManyOptions<T> = {},
)
| 433 | } |
| 434 | |
| 435 | override async nativeUpdateMany<T extends object>( |
| 436 | entityName: EntityName<T>, |
| 437 | where: FilterQuery<T>[], |
| 438 | data: EntityDictionary<T>[], |
| 439 | options: NativeInsertUpdateOptions<T> & UpsertManyOptions<T> = {}, |
| 440 | ): Promise<QueryResult<T>> { |
| 441 | where = where.map(row => { |
| 442 | if (Utils.isPlainObject(row)) { |
| 443 | return this.renameFields(entityName, row as T, true); |
| 444 | } |
| 445 | |
| 446 | return row; |
| 447 | }); |
| 448 | data = data.map(row => { |
| 449 | this.handleVersionProperty(entityName, row, true); |
| 450 | return this.renameFields(entityName, row); |
| 451 | }); |
| 452 | options = { ...options }; |
| 453 | |
| 454 | const meta = this.metadata.find(entityName); |
| 455 | /* v8 ignore next */ |
| 456 | const rename = (field: keyof T) => |
| 457 | meta ? ((meta.properties[field as EntityKey<T>]?.fieldNames[0] as keyof T) ?? field) : field; |
| 458 | |
| 459 | if (options.onConflictFields && Array.isArray(options.onConflictFields)) { |
| 460 | options.onConflictFields = options.onConflictFields.map(rename); |
| 461 | } |
| 462 | |
| 463 | if (options.onConflictMergeFields) { |
| 464 | options.onConflictMergeFields = options.onConflictMergeFields.map(rename) as never[]; |
| 465 | } |
| 466 | |
| 467 | if (options.onConflictExcludeFields) { |
| 468 | options.onConflictExcludeFields = options.onConflictExcludeFields.map(rename) as never[]; |
| 469 | } |
| 470 | |
| 471 | /* v8 ignore next */ |
| 472 | const pk = meta?.getPrimaryProps()[0].fieldNames[0] ?? '_id'; |
| 473 | const res = await this.rethrow( |
| 474 | this.getConnection('write').bulkUpdateMany<T>( |
| 475 | entityName, |
| 476 | where as object[], |
| 477 | data as object[], |
| 478 | options.ctx, |
| 479 | options.upsert, |
| 480 | options, |
| 481 | options.signal, |
| 482 | ), |
| 483 | ); |
| 484 | |
| 485 | if (res.insertedIds) { |
| 486 | let i = 0; |
| 487 | res.rows = where.map(cond => { |
| 488 | if (Utils.isEmpty(cond)) { |
| 489 | return { [pk]: res.insertedIds![i++] }; |
| 490 | } |
| 491 | |
| 492 | return { [pk]: cond[pk as EntityKey] }; |
nothing calls this directly
no test coverage detected