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

Method having

packages/sql/src/query/QueryBuilder.ts:1872–1900  ·  view source on GitHub ↗

* 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,
  )

Source from the content-addressed store, hash-verified

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,

Callers 2

andHavingMethod · 0.95
orHavingMethod · 0.95

Calls 4

ensureNotFinalizedMethod · 0.95
rawFunction · 0.90
createNodeMethod · 0.80
processMethod · 0.65

Tested by

no test coverage detected