Documentation
    Preparing search index...

    Interface FindAndCountOptions<TAttributes>

    Options for Model.count method

    interface FindAndCountOptions<TAttributes = any> {
        attributes?: FindAttributeOptions<TAttributes>;
        benchmark?: boolean;
        bind?: BindOrReplacements;
        col?: string;
        connection?: AbstractConnection | null;
        countGroupedRows?: boolean;
        distinct?: boolean;
        fieldMap?: FieldMap;
        group?: GroupOption;
        groupedLimit?: unknown;
        having?: WhereOptions<any>;
        include?: AllowArray<Includeable>;
        indexHints?: IndexHint[];
        instance?: Model<any, any>;
        limit?: number | Nullish | Literal;
        lock?: boolean | Lock | { level: Lock; of: ModelStatic<Model<any, any>> };
        logging?: false | ((sql: string, timing?: number) => void);
        mapToModel?: boolean;
        maxExecutionTimeHintMs?: number;
        minifyAliases?: boolean;
        nest?: boolean;
        offset?: number | Nullish | Literal;
        order?: Order;
        paranoid?: boolean;
        plain?: boolean;
        raw?: boolean;
        rejectOnEmpty?: boolean | Error;
        replacements?: BindOrReplacements;
        retry?: Options;
        searchPath?: string;
        skipLocked?: boolean;
        subQuery?: boolean;
        supportsSearchPath?: boolean;
        tableHints?: TableHints[];
        transaction?: Transaction | null;
        type?: string;
        useMaster?: boolean;
        where?: WhereOptions<TAttributes>;
    }

    Type Parameters

    • TAttributes = any

    Hierarchy (View Summary)

    Index

    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.

    { 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

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

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

    Either an object of named parameter bindings in the format $param or an array of unnamed values to bind to $1, $2, etc in your SQL.

    col?: string

    Column on which COUNT() should be applied

    connection?: AbstractConnection | null

    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.

    countGroupedRows?: boolean

    Count number of records returned by group by Used in conjunction with group.

    distinct?: boolean

    Apply COUNT(DISTINCT(col))

    fieldMap?: FieldMap

    Map returned fields to arbitrary names for SELECT query type if options.fieldMaps is present.

    group?: GroupOption

    GROUP BY in sql Used in conjunction with attributes.

    Projectable

    groupedLimit?: unknown
    having?: WhereOptions<any>

    Select group rows after groups and aggregates are computed.

    Include options. See find for details

    indexHints?: IndexHint[]

    MySQL only.

    instance?: Model<any, any>

    A sequelize instance used to build the return instance

    limit?: number | Nullish | Literal

    Limits how many items will be retrieved by the operation.

    If limit and include are used together, Sequelize will turn the subQuery option on by default. This is done to ensure that limit only impacts the Model on the same level as the limit option.

    You can disable this behavior by explicitly setting subQuery: false, however limit will then affect the total count of returned values, including eager-loaded associations, instead of just one table.

    // in the following query, `limit` only affects the "User" model.
    // This will return 2 users, each including all of their projects.
    User.findAll({
    limit: 2,
    include: [User.associations.projects],
    });
    // in the following query, `limit` affects the total number of returned values, eager-loaded associations included.
    // This may return 2 users, each with one project,
    // or 1 user with 2 projects.
    User.findAll({
    limit: 2,
    include: [User.associations.projects],
    subQuery: false,
    });
    lock?: boolean | Lock | { level: Lock; of: ModelStatic<Model<any, any>> }

    Lock the selected rows. Possible options are transaction.LOCK.UPDATE and transaction.LOCK.SHARE. Postgres also supports transaction.LOCK.KEY_SHARE, transaction.LOCK.NO_KEY_UPDATE and specific model locks with joins. See Lock.

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

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

    mapToModel?: boolean

    Map returned fields to model's fields if options.model or options.instance is present. Mapping will occur before building the model instance.

    maxExecutionTimeHintMs?: number

    This sets the max execution time for MySQL.

    minifyAliases?: boolean

    Controls whether aliases are minified in this query. This overrides the global option

    nest?: boolean

    If true, transforms objects with . separated property names into nested objects using dottie.js. For example { 'user.username': 'john' } becomes { user: { username: 'john' }}. When nest is true, the query type is assumed to be 'SELECT', unless otherwise specified

    false
    
    offset?: number | Nullish | Literal

    Skip the first n items of the results.

    order?: Order

    Specifies an ordering. If a string is provided, it will be escaped.

    Using an array, you can provide several attributes / functions to order by. Each element can be further wrapped in a two-element array:

    • The first element is the column / function to order by,
    • the second is the direction.
    `order: [['name', 'DESC']]`.

    The attribute will be escaped, but the direction will not.
    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.

    true
    
    plain?: boolean

    Sets the query type to SELECT and return a single row

    raw?: boolean

    Return raw result. See Sequelize#query for more information.

    rejectOnEmpty?: boolean | Error

    Throws an error if the query would return 0 results.

    replacements?: BindOrReplacements

    Either an object of named parameter replacements in the format :param or an array of unnamed replacements to replace ? in your SQL.

    retry?: Options
    searchPath?: string

    An optional parameter to specify the schema search_path (Postgres only)

    skipLocked?: boolean

    Skip locked rows. Only supported in Postgres.

    subQuery?: boolean

    Use sub queries (internal).

    If unspecified, this will true by default if limit is specified, and false otherwise. See FindOptions#limit for more information.

    supportsSearchPath?: boolean

    If false do not prepend the query with the search_path (Postgres only)

    tableHints?: TableHints[]

    Use a table hint for the query, only supported in MSSQL.

    transaction?: Transaction | null

    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.

    type?: string

    The type of query you are executing. The query type affects how results are formatted before they are passed back. The type is a string, but Sequelize.QueryTypes is provided as convenience shortcuts.

    useMaster?: boolean

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

    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.