* Creates a COUNT query to count matching rows. * * @example * ```ts * const count = await em.createQueryBuilder(User) * .count() * .where({ isActive: true }) * .execute('get'); * ```
(field?: F | F[], distinct = false)
| 973 | * ``` |
| 974 | */ |
| 975 | count<F extends Field<Entity, RootAlias, Context>>(field?: F | F[], distinct = false): CountQueryBuilder<Entity> { |
| 976 | if (field) { |
| 977 | this.#state.fields = Utils.asArray(field as string); |
| 978 | } else if (distinct || this.hasToManyJoins()) { |
| 979 | this.#state.fields = this.mainAlias.meta.primaryKeys; |
| 980 | } else { |
| 981 | this.#state.fields = [raw('*')]; |
| 982 | } |
| 983 | |
| 984 | if (distinct) { |
| 985 | this.#state.flags.add(QueryFlag.DISTINCT); |
| 986 | } |
| 987 | |
| 988 | return this.init(QueryType.COUNT) as unknown as CountQueryBuilder<Entity>; |
| 989 | } |
| 990 | |
| 991 | /** |
| 992 | * Adds a JOIN clause to the query for an entity relation. |
nothing calls this directly
no test coverage detected