(
fields: unknown,
distinct = false,
)
| 771 | CTEs |
| 772 | >; |
| 773 | select( |
| 774 | fields: unknown, |
| 775 | distinct = false, |
| 776 | ): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, any, CTEs> { |
| 777 | this.ensureNotFinalized(); |
| 778 | this.#state.fields = Utils.asArray(fields as Field<Entity, RootAlias, Context>[]).flatMap(f => { |
| 779 | if (typeof f !== 'string') { |
| 780 | // Normalize sql.ref('prop') and sql.ref('prop').as('alias') to string form |
| 781 | if (isRaw(f) && f.sql === '??' && f.params.length === 1) { |
| 782 | return this.resolveNestedPath(String(f.params[0])); |
| 783 | } |
| 784 | |
| 785 | if (isRaw(f) && f.sql === '?? as ??' && f.params.length === 2) { |
| 786 | return `${this.resolveNestedPath(String(f.params[0]))} as ${String(f.params[1])}`; |
| 787 | } |
| 788 | |
| 789 | return f; |
| 790 | } |
| 791 | |
| 792 | const asMatch = FIELD_ALIAS_RE.exec(f); |
| 793 | |
| 794 | if (asMatch) { |
| 795 | return `${this.resolveNestedPath(asMatch[1].trim())} as ${asMatch[2]}`; |
| 796 | } |
| 797 | |
| 798 | return this.resolveNestedPath(f); |
| 799 | }) as any; |
| 800 | |
| 801 | if (distinct) { |
| 802 | this.#state.flags.add(QueryFlag.DISTINCT); |
| 803 | } |
| 804 | |
| 805 | return this.init(QueryType.SELECT) as any; |
| 806 | } |
| 807 | |
| 808 | /** |
| 809 | * Adds fields to an existing SELECT query. |
no test coverage detected