(
entityName: EntityName<T>,
where: FilterQuery<T>,
options: StreamOptions<T, any>,
)
| 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>, |
nothing calls this directly
no test coverage detected