* Adds a HAVING clause to the query, typically used with GROUP BY. * * @example * ```ts * qb.select([raw('count(*) as count'), 'status']) * .groupBy('status') * .having({ count: { $gt: 5 } }); * ```
(
cond: QBFilterQuery<Entity, RootAlias, Context, RawAliases> | string = {},
params?: any[],
operator?: keyof typeof GroupOperator,
)
| 1870 | * ``` |
| 1871 | */ |
| 1872 | having( |
| 1873 | cond: QBFilterQuery<Entity, RootAlias, Context, RawAliases> | string = {}, |
| 1874 | params?: any[], |
| 1875 | operator?: keyof typeof GroupOperator, |
| 1876 | ): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields, CTEs> { |
| 1877 | this.ensureNotFinalized(); |
| 1878 | |
| 1879 | if (typeof cond === 'string') { |
| 1880 | cond = { [raw(`(${cond})`, params)]: [] } as QBFilterQuery<Entity, RootAlias, Context, RawAliases>; |
| 1881 | } |
| 1882 | |
| 1883 | const processed = CriteriaNodeFactory.createNode<Entity>( |
| 1884 | this.metadata, |
| 1885 | this.mainAlias.entityName, |
| 1886 | cond as FilterQuery<Entity>, |
| 1887 | undefined, |
| 1888 | undefined, |
| 1889 | false, |
| 1890 | ).process(this as IQueryBuilder<Entity>, { type: 'having' }); |
| 1891 | |
| 1892 | if (!this.#state.having || !operator) { |
| 1893 | this.#state.having = processed as FilterQuery<Entity>; |
| 1894 | } else { |
| 1895 | const cond1 = [this.#state.having, processed]; |
| 1896 | this.#state.having = { [operator]: cond1 }; |
| 1897 | } |
| 1898 | |
| 1899 | return this as SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields, CTEs>; |
| 1900 | } |
| 1901 | |
| 1902 | andHaving( |
| 1903 | cond?: QBFilterQuery<Entity, RootAlias, Context, RawAliases> | string, |
no test coverage detected