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

Function streamFromVirtual

packages/sql/src/AbstractSqlDriver.ts:380–425  ·  view source on GitHub ↗
(
    entityName: EntityName<T>,
    where: FilterQuery<T>,
    options: StreamOptions<T, any>,
  )

Source from the content-addressed store, hash-verified

378 }
379
380 protected async *streamFromVirtual<T extends object>(
381 entityName: EntityName<T>,
382 where: FilterQuery<T>,
383 options: StreamOptions<T, any>,
384 ): AsyncIterableIterator<EntityData<T>> {
385 const meta = this.metadata.get<T>(entityName);
386
387 /* v8 ignore next */
388 if (!meta.expression) {
389 return;
390 }
391
392 if (typeof meta.expression === 'string') {
393 yield* this.wrapVirtualExpressionInSubqueryStream(meta, meta.expression, where, options, QueryType.SELECT);
394 return;
395 }
396
397 const em = this.createEntityManager();
398 em.setTransactionContext(options.ctx);
399 const res = meta.expression(em, where as any, options as FindOptions<T, any, any, any>, true);
400
401 if (typeof res === 'string') {
402 yield* this.wrapVirtualExpressionInSubqueryStream(meta, res, where, options, QueryType.SELECT);
403 return;
404 }
405
406 if (res instanceof QueryBuilder) {
407 yield* this.wrapVirtualExpressionInSubqueryStream(
408 meta,
409 res.getFormattedQuery(),
410 where,
411 options,
412 QueryType.SELECT,
413 );
414 return;
415 }
416
417 if (isRaw(res)) {
418 const expr = this.platform.formatQuery(res.sql, res.params);
419 yield* this.wrapVirtualExpressionInSubqueryStream(meta, expr, where, options, QueryType.SELECT);
420 return;
421 }
422
423 /* v8 ignore next */
424 yield* res as EntityData<T>[];
425 }
426
427 protected async wrapVirtualExpressionInSubquery<T extends object>(
428 meta: EntityMetadata<T>,

Callers

nothing calls this directly

Calls 6

isRawFunction · 0.90
getFormattedQueryMethod · 0.80
formatQueryMethod · 0.80
getMethod · 0.65
createEntityManagerMethod · 0.65
setTransactionContextMethod · 0.65

Tested by

no test coverage detected