(
entityName: EntityName<T>,
data: EntityDictionary<T>[],
options: NativeInsertUpdateManyOptions<T> = {},
)
| 62 | } |
| 63 | |
| 64 | override async nativeInsertMany<T extends object>( |
| 65 | entityName: EntityName<T>, |
| 66 | data: EntityDictionary<T>[], |
| 67 | options: NativeInsertUpdateManyOptions<T> = {}, |
| 68 | ): Promise<QueryResult<T>> { |
| 69 | options.processCollections ??= true; |
| 70 | options.convertCustomTypes ??= true; |
| 71 | const meta = this.metadata.get<T>(entityName); |
| 72 | const pks = this.getPrimaryKeyFields(meta) as EntityKey<T>[]; |
| 73 | const collections = options.processCollections ? data.map(d => this.extractManyToMany(meta, d)) : []; |
| 74 | const qb = this.createQueryBuilder<T>(entityName, options.ctx, 'write', options.convertCustomTypes).withSchema( |
| 75 | this.getSchemaName(meta, options), |
| 76 | ); |
| 77 | qb.insert(data as RequiredEntityData<T>[]); |
| 78 | |
| 79 | const res = await this.rethrow(qb.execute('run')); |
| 80 | let pk: any[]; |
| 81 | |
| 82 | if (pks.length > 1) { |
| 83 | // owner has composite pk |
| 84 | pk = data.map(d => Utils.getPrimaryKeyCond(d as T, pks)); |
| 85 | } else { |
| 86 | res.row ??= {}; |
| 87 | res.rows ??= []; |
| 88 | pk = data.map((d, i) => d[pks[0]] ?? res.rows![i]?.[pks[0]]).map(d => [d]); |
| 89 | res.insertId = res.insertId || res.row![pks[0]]; |
| 90 | } |
| 91 | |
| 92 | for (let i = 0; i < collections.length; i++) { |
| 93 | await this.processManyToMany<T>(meta, pk[i], collections[i], false, options); |
| 94 | } |
| 95 | |
| 96 | return res; |
| 97 | } |
| 98 | |
| 99 | override async nativeUpdateMany<T extends object>( |
| 100 | entityName: EntityName<T>, |
nothing calls this directly
no test coverage detected