(
cond: QBFilterQuery<Entity, RootAlias, Context, RawAliases> | string | RawQueryFragment,
params?: keyof typeof GroupOperator | any[],
operator?: keyof typeof GroupOperator,
)
| 1556 | */ |
| 1557 | where(cond: string | RawQueryFragment, params?: any[], operator?: keyof typeof GroupOperator): this; |
| 1558 | where( |
| 1559 | cond: QBFilterQuery<Entity, RootAlias, Context, RawAliases> | string | RawQueryFragment, |
| 1560 | params?: keyof typeof GroupOperator | any[], |
| 1561 | operator?: keyof typeof GroupOperator, |
| 1562 | ): this { |
| 1563 | this.ensureNotFinalized(); |
| 1564 | let processedCond: FilterQuery<Entity>; |
| 1565 | |
| 1566 | if (isRaw(cond)) { |
| 1567 | const sql = this.platform.formatQuery(cond.sql, cond.params); |
| 1568 | processedCond = { [raw(`(${sql})`)]: Utils.asArray(params) } as FilterQuery<Entity>; |
| 1569 | operator ??= '$and'; |
| 1570 | } else if (typeof cond === 'string') { |
| 1571 | processedCond = { [raw(`(${cond})`, Utils.asArray(params))]: [] } as FilterQuery<Entity>; |
| 1572 | operator ??= '$and'; |
| 1573 | } else { |
| 1574 | processedCond = QueryHelper.processWhere({ |
| 1575 | where: cond as FilterQuery<Entity>, |
| 1576 | entityName: this.mainAlias.entityName, |
| 1577 | metadata: this.metadata, |
| 1578 | platform: this.platform, |
| 1579 | aliasMap: this.getAliasMap(), |
| 1580 | aliased: [QueryType.SELECT, QueryType.COUNT].includes(this.type), |
| 1581 | convertCustomTypes: this.#state.flags.has(QueryFlag.CONVERT_CUSTOM_TYPES), |
| 1582 | }) as FilterQuery<Entity>; |
| 1583 | } |
| 1584 | |
| 1585 | const op = operator || (params as keyof typeof GroupOperator); |
| 1586 | const topLevel = |
| 1587 | !op || !(Utils.hasObjectKeys(this.#state.cond) || RawQueryFragment.hasObjectFragments(this.#state.cond)); |
| 1588 | const criteriaNode = CriteriaNodeFactory.createNode<Entity>( |
| 1589 | this.metadata, |
| 1590 | this.mainAlias.entityName, |
| 1591 | processedCond, |
| 1592 | ); |
| 1593 | const ignoreBranching = this.#state.resolvedPopulateWhere === 'infer'; |
| 1594 | |
| 1595 | if ( |
| 1596 | [QueryType.UPDATE, QueryType.DELETE].includes(this.type) && |
| 1597 | criteriaNode.willAutoJoin(this as IQueryBuilder<Entity>, undefined, { ignoreBranching }) |
| 1598 | ) { |
| 1599 | // use sub-query to support joining |
| 1600 | this.setFlag(this.type === QueryType.UPDATE ? QueryFlag.UPDATE_SUB_QUERY : QueryFlag.DELETE_SUB_QUERY); |
| 1601 | this.select(this.mainAlias.meta.primaryKeys, true); |
| 1602 | } |
| 1603 | |
| 1604 | if (topLevel) { |
| 1605 | this.#state.cond = criteriaNode.process(this as IQueryBuilder<Entity>, { ignoreBranching }); |
| 1606 | } else if (Array.isArray(this.#state.cond[op])) { |
| 1607 | this.#state.cond[op].push(criteriaNode.process(this as IQueryBuilder<Entity>, { ignoreBranching })); |
| 1608 | } else { |
| 1609 | const cond1 = [this.#state.cond, criteriaNode.process(this as IQueryBuilder<Entity>, { ignoreBranching })]; |
| 1610 | this.#state.cond = { [op]: cond1 }; |
| 1611 | } |
| 1612 | |
| 1613 | if (this.#state.onConflict) { |
| 1614 | this.#state.onConflict[this.#state.onConflict.length - 1].where = this.helper.processOnConflictCondition( |
| 1615 | this.#state.cond, |
no test coverage detected