OptionalwhereOptionalattributesOptionalwithAssociation aliases to count without loading their rows. Each sets
<alias>Count on every returned row.
const users = await User.findAll({ withCount: ['posts'] });
users[0].postsCount; // number
Resolved with one grouped query per association, so the statement count
does not grow with the number of parent rows. Prefer this over a full
include when you only need the size.
OptionalschemaSchema to use for the main table
OptionaltableOverrides the FROM target of the query, in place of the model's own
table name. Primarily useful together with cte to select from a CTE
result set instead of the model's base table
OptionalsearchSearch path for query resolution (PostgreSQL)
OptionalusingConnection name to use for this query Allows querying a different database connection
OptionalincludeOptionalorderOptionallimitNumber of records to return
OptionaloffsetNumber of records to skip
OptionalgroupGROUP BY clause - can be a string, array of strings, array of arrays with function expressions, or array of model objects
OptionalgroupType of grouping for advanced aggregation features
OptionalgroupingGROUPING SETS - custom grouping combinations for advanced aggregation Each element is an array representing one grouping set
OptionalhavingHAVING clause - filter aggregated results Supports all WHERE operators plus aggregation-specific conditions
OptionalrawOptionaltransactionOptionallockRow-level locking options
OptionalbenchmarkOptionalloggingOptionalbenchmarkOptionalparanoidWhen true, includes soft-deleted records in query results. When false or undefined, excludes soft-deleted records (default behavior for paranoid models).
OptionalunionUNION type for combining multiple queries
OptionalunionArray of union queries to combine with the main query
OptionalsubSubquery support - allows using literal SQL in where clauses Usage: { id: { [Op.in]: prorm.literal('(SELECT id FROM users)') } }
OptionalsubqueryWhether to use subquery for includes. When false, uses JOIN instead of IN (SELECT) for includes. When true (default), uses subquery IN pattern for includes.
OptionaldistinctWhen true, applies DISTINCT to the query to remove duplicate rows. Useful when using aggregate functions with includes that may cause duplicates.
OptionalcteCommon Table Expressions (CTEs) to use in the query Supports both regular WITH and WITH RECURSIVE
// Simple CTE
cte: [{ name: 'active_users', query: 'SELECT * FROM users WHERE active = true' }]
// Recursive CTE for hierarchy
cte: [{
name: 'org_chart',
columns: ['id', 'name', 'manager_id'],
query: `SELECT id, name, manager_id FROM employees WHERE manager_id IS NULL
UNION ALL
SELECT e.id, e.name, e.manager_id FROM employees e
INNER JOIN org_chart o ON e.manager_id = o.id`,
recursive: true
}]
OptionalstreamEnable streaming results for large datasets When true, returns a ReadableStream instead of waiting for all results
OptionalstreamBatch size for streaming results
OptionaltransformTransform function to apply to each record during streaming
OptionalstreamHigh watermark for the stream (internal buffer size)
OptionaldefaultsDefault values to use when creating a new record if not found
OptionalhooksWhether to run beforeCreate/afterCreate hooks (default: true)
OptionalvalidateWhether to validate the model before creation (default: true)
Options for
findOrCreate: the search criteria plus thedefaultsused only when nothing matched.