# query.autoCountQuery() function · @imqueue/pg-sequelize

Source: https://imqueue.org/api/pg-sequelize/latest/pg-sequelize.query.autocountquery/
Published: 2026-08-01
Author: @imqueue maintainers (https://github.com/imqueue)
Package: @imqueue/pg-sequelize 4.2.0 — generated reference, not hand-written

The counting counterpart of [query.autoQuery()](https://imqueue.org/api/pg-sequelize/latest/pg-sequelize.query.autoquery/), for the same fields and filter.

**Signature:**

```typescript
export function autoCountQuery(model: any, fields?: any, ...merge: (Partial<CountOptions> | undefined)[]): CountOptions;
```

## Parameters


| Parameter | Type | Description |
| --- | --- | --- |
| model | any | Model to count rows of. |
| fields | any | _(Optional)_ The same fields map used for the data query. |
| merge | (Partial<CountOptions> \| undefined)\[\] | The same filter fragments, minus limit and order. |


**Returns:**

CountOptions

Count options ready for `Model.count()`.

## Remarks

Builds the same query, then drops `attributes` and counts distinct primary keys instead — `distinct` matters because the joins `autoQuery` adds would otherwise multiply a row once per joined record and inflate the total.

Pass it the same `fields` and filter as the data query, or the two disagree.

