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

Method fromVirtual

packages/sql/src/query/QueryBuilder.ts:2961–2983  ·  view source on GitHub ↗
(meta: EntityMetadata<T>)

Source from the content-addressed store, hash-verified

2959 }
2960
2961 private fromVirtual<T extends object>(meta: EntityMetadata<T>): string {
2962 if (typeof meta.expression === 'string') {
2963 return `(${meta.expression}) as ${this.platform.quoteIdentifier(this.alias)}`;
2964 }
2965
2966 const res = meta.expression!(this.em, this.#state.cond as any, {});
2967
2968 if (typeof res === 'string') {
2969 return `(${res}) as ${this.platform.quoteIdentifier(this.alias)}`;
2970 }
2971
2972 if (res instanceof QueryBuilder) {
2973 return `(${res.getFormattedQuery()}) as ${this.platform.quoteIdentifier(this.alias)}`;
2974 }
2975
2976 if (isRaw(res)) {
2977 const query = this.platform.formatQuery(res.sql, res.params);
2978 return `(${query}) as ${this.platform.quoteIdentifier(this.alias)}`;
2979 }
2980
2981 /* v8 ignore next */
2982 return res as unknown as string;
2983 }
2984
2985 /**
2986 * Adds a join from a property object. Used internally for TPT joins where the property

Callers 1

getQueryBaseMethod · 0.95

Calls 4

isRawFunction · 0.90
getFormattedQueryMethod · 0.80
formatQueryMethod · 0.80
quoteIdentifierMethod · 0.45

Tested by

no test coverage detected