MCPcopy Create free account
hub / github.com/mikro-orm/mikro-orm / nativeInsertMany

Method nativeInsertMany

packages/oracledb/src/OracleDriver.ts:64–97  ·  view source on GitHub ↗
(
    entityName: EntityName<T>,
    data: EntityDictionary<T>[],
    options: NativeInsertUpdateManyOptions<T> = {},
  )

Source from the content-addressed store, hash-verified

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>,

Callers

nothing calls this directly

Calls 9

createQueryBuilderMethod · 0.95
rethrowMethod · 0.80
getPrimaryKeyCondMethod · 0.80
getMethod · 0.65
withSchemaMethod · 0.65
getSchemaNameMethod · 0.65
insertMethod · 0.65
executeMethod · 0.65
mapMethod · 0.45

Tested by

no test coverage detected