Interface CountOptions<TAttributes>

Options for Model.count method

interface CountOptions<TAttributes> {
    [COMPLETES_TRANSACTION]?: boolean;
    attributes?: FindAttributeOptions<TAttributes>;
    benchmark?: boolean;
    col?: string;
    connection?: null | AbstractConnection;
    distinct?: boolean;
    group?: GroupOption;
    include?: AllowArray<Includeable>;
    logging?: false | ((sql, timing?) => void);
    maxExecutionTimeHintMs?: number;
    paranoid?: boolean;
    transaction?: null | Transaction;
    useMaster?: boolean;
    where?: WhereOptions<TAttributes>;
}

Type Parameters

  • TAttributes = any

Hierarchy (view full)

Properties

[COMPLETES_TRANSACTION]?: boolean

Indicates if the query completes the transaction Internal only

If an array: a list of the attributes that you want to select. Attributes can also be raw SQL (literal), fn, col, and cast

To rename an attribute, you can pass an array, with two elements:

  • The first is the name of the attribute (or literal, fn, col, cast),
  • and the second is the name to give to that attribute in the returned instance.

If include is used: selects all the attributes of the model, plus some additional ones. Useful for aggregations.

Example

{ attributes: { include: [[literal('COUNT(id)'), 'total']] }

If exclude is used: selects all the attributes of the model, except the one specified in exclude. Useful for security purposes

Example

{ attributes: { exclude: ['password'] } }
benchmark?: boolean

Pass query execution time in milliseconds as second argument to logging function (options.logging).

col?: string

Column on which COUNT() should be applied

connection?: null | AbstractConnection

The connection on which this query must be run. Mutually exclusive with Transactionable.transaction.

Can be used to ensure that a query is run on the same connection as a previous query, which is useful when configuring session options.

Specifying this option takes precedence over CLS Transactions. If a transaction is running in the current AsyncLocalStorage context, it will be ignored in favor of the specified connection.

distinct?: boolean

Apply COUNT(DISTINCT(col))

group?: GroupOption

GROUP BY in sql Used in conjunction with attributes.

See

Projectable

Include options. See find for details

logging?: false | ((sql, timing?) => void)

A function that gets executed while running the query to log the sql.

Type declaration

    • (sql, timing?): void
    • Parameters

      • sql: string
      • Optional timing: number

      Returns void

maxExecutionTimeHintMs?: number

This sets the max execution time for MySQL.

paranoid?: boolean

If true, only non-deleted records will be returned. If false, both deleted and non-deleted records will be returned.

Only applies if InitOptions.paranoid is true for the model.

Default

true
transaction?: null | Transaction

The transaction in which this query must be run. Mutually exclusive with Transactionable.connection.

If the Sequelize disableClsTransactions option has not been set to true, and a transaction is running in the current AsyncLocalStorage context, that transaction will be used, unless null or another Transaction is manually specified here.

useMaster?: boolean

Force the query to use the write pool, regardless of the query type.

Default

false

The WHERE clause. Can be many things from a hash of attributes to raw SQL.

Visit https://sequelize.org/docs/v7/core-concepts/model-querying-basics/ for more information.