(
entityName: EntityName<T>,
where: FilterQuery<T>,
data: EntityDictionary<T>,
options: NativeInsertUpdateOptions<T> & UpsertOptions<T> = {},
)
| 388 | } |
| 389 | |
| 390 | async nativeUpdate<T extends object>( |
| 391 | entityName: EntityName<T>, |
| 392 | where: FilterQuery<T>, |
| 393 | data: EntityDictionary<T>, |
| 394 | options: NativeInsertUpdateOptions<T> & UpsertOptions<T> = {}, |
| 395 | ): Promise<QueryResult<T>> { |
| 396 | if (Utils.isPrimaryKey(where)) { |
| 397 | where = this.buildFilterById(entityName, where as string); |
| 398 | } |
| 399 | |
| 400 | this.handleVersionProperty(entityName, data, true); |
| 401 | data = this.renameFields(entityName, data); |
| 402 | where = this.renameFields(entityName, where as T, true); |
| 403 | options = { ...options }; |
| 404 | |
| 405 | const meta = this.metadata.find(entityName); |
| 406 | /* v8 ignore next */ |
| 407 | const rename = (field: keyof T) => |
| 408 | meta ? ((meta.properties[field as EntityKey<T>]?.fieldNames[0] as keyof T) ?? field) : field; |
| 409 | |
| 410 | if (options.onConflictFields && Array.isArray(options.onConflictFields)) { |
| 411 | options.onConflictFields = options.onConflictFields.map(rename); |
| 412 | } |
| 413 | |
| 414 | if (options.onConflictMergeFields) { |
| 415 | options.onConflictMergeFields = options.onConflictMergeFields.map(rename) as never[]; |
| 416 | } |
| 417 | |
| 418 | if (options.onConflictExcludeFields) { |
| 419 | options.onConflictExcludeFields = options.onConflictExcludeFields.map(rename) as never[]; |
| 420 | } |
| 421 | |
| 422 | return this.rethrow( |
| 423 | this.getConnection('write').updateMany<T>( |
| 424 | entityName, |
| 425 | where as object, |
| 426 | data as object, |
| 427 | options.ctx, |
| 428 | options.upsert, |
| 429 | options, |
| 430 | options.signal, |
| 431 | ), |
| 432 | ); |
| 433 | } |
| 434 | |
| 435 | override async nativeUpdateMany<T extends object>( |
| 436 | entityName: EntityName<T>, |
nothing calls this directly
no test coverage detected