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

Method insertFrom

packages/sql/src/query/QueryBuilder.ts:905–918  ·  view source on GitHub ↗

* Creates an INSERT ... SELECT query that copies rows from the source query. * * Column resolution (3 tiers): * 1. No explicit select on source, no explicit columns → all cloneable columns derived from entity metadata * 2. Explicit select on source, no explicit columns → columns derived

(
    subQuery: QueryBuilder<any>,
    options?: { columns?: Field<Entity, RootAlias, Context>[] },
  )

Source from the content-addressed store, hash-verified

903 * ```
904 */
905 insertFrom(
906 subQuery: QueryBuilder<any>,
907 options?: { columns?: Field<Entity, RootAlias, Context>[] },
908 ): InsertQueryBuilder<Entity, RootAlias, Context> {
909 this.ensureNotFinalized();
910 this.#state.type = QueryType.INSERT;
911 this.#state.insertSubQuery = subQuery;
912
913 if (options?.columns) {
914 this.#state.insertColumns = Utils.asArray(options.columns as string[]);
915 }
916
917 return this as unknown as InsertQueryBuilder<Entity, RootAlias, Context>;
918 }
919
920 /**
921 * Creates an UPDATE query with the given data.

Callers 3

nativeCloneSimpleFunction · 0.80
nativeCloneTPTFunction · 0.80
clone.test.tsFile · 0.80

Calls 2

ensureNotFinalizedMethod · 0.95
asArrayMethod · 0.80

Tested by

no test coverage detected