Class AbstractQueryGenerator<Dialect>

The base class for all query generators, used to generate all SQL queries.

The implementation varies between SQL dialects, and is overridden by subclasses. You can access your dialect's version through Sequelize#queryGenerator.

Type Parameters

Hierarchy (View Summary)

Constructors

Properties

dialect: Dialect

Accessors

Methods

  • Generates a dialect-aware COUNT(*) wrapper around a subquery.

    This utility is used to compute the total number of rows returned by an arbitrary SQL query by wrapping it in:

    SELECT COUNT(*) AS count FROM ()

    The alias token is generated through getAliasToken, so dialects that do not support the AS keyword (e.g. Oracle) are handled correctly.

    Parameters

    • query: string

      The SQL query to wrap inside the COUNT(*) subquery.

    Returns string

    const subQuery = `SELECT * FROM "Users" WHERE "active" = true`;
    const countQuery = queryGenerator.generateCountAllQuery(subQuery);
    // SELECT COUNT(*) AS count FROM (SELECT * FROM "Users" WHERE "active" = true) AS Z
    // (Oracle)
    // SELECT COUNT(*) AS count FROM (SELECT * FROM "Users" WHERE "active" = true) Z
  • Parameters

    • _sqlExpression: string

      ⚠️ This is not an identifier, it's a raw SQL expression. It will be inlined in the query.

    • _path: readonly (string | number)[]

      The JSON path, where each item is one level of the path

    • _unquote: boolean

      Whether the result should be unquoted (depending on dialect: ->> and #>> operators, json_unquote function). Defaults to false.

    Returns string