OptionalschemaSchema the model belongs to
Static property indicating this is a model class (always false for static check)
OptionalisCheck if this model is a materialized view
Add a column to this model's table.
Optionaloptions: QueryInterfaceOptionsRemove a column from this model's table.
Optionaloptions: QueryInterfaceOptionsChange a column's definition.
Optionaloptions: QueryInterfaceOptionsRename a column.
Optionaloptions: QueryInterfaceOptionsAdd an index to this model's table.
OptionalfieldsOrOptions: string[] | IndexFieldDefinition[] | IndexOptions & QueryInterfaceOptionsOptionaloptions: IndexOptions & QueryInterfaceOptionsRemove an index by name.
Optionaloptions: QueryInterfaceOptionsList this model's indexes.
Whether an index exists on this model's table.
Create a full-text index; table defaults to this model.
Add a constraint to this model's table.
OptionalconstraintOrOptions: ConstraintDefinitionOptionaloptions: QueryInterfaceOptionsRemove a constraint by name.
OptionaltypeOrOptions: string | QueryInterfaceOptionsList this model's constraints.
List the foreign keys on this model's table.
Whether this model's table exists in the database.
Rename this model's table. Does not update the model's own tableName.
Optionaloptions: QueryInterfaceOptionsTurn row-level security on for this model's table.
Turn row-level security off.
Create a policy on this model's table; table defaults to this model.
Drop a policy from this model's table.
Optionaloptions: { ifExists?: boolean }Create a trigger on this model's table; table defaults to this model.
Drop a trigger from this model's table.
Optionaloptions: { ifExists?: boolean }Create a partition of this model's table; parentTable defaults to it.
Attach an existing table as a partition of this model's table.
Detach a partition from this model's table.
Drop a partition of this model's table.
Optionaloptions: { ifExists?: boolean; cascade?: boolean } & QueryInterfaceOptionsDescribe this model's table as the database reports it.
Build a WHERE condition using operator symbols
Optionalvalue: unknownOptionaloptions: FindOptionsOptionaloptions: FindOptionsFind all records matching the given options and return both rows and total count
Optionaloptions: FindOptionsObject with rows array and count total
// Basic find and count all
const result = await User.findAndCountAll();
console.log(result.count); // total number of matching records
console.log(result.rows); // array of model instances
Optionalvalues: Partial<T>Optionaloptions: CreateOptionsRestore soft-deleted records (set deletedAt to NULL)
Optionaloptions: RestoreOptions & { where?: WhereOptions<any> }
Restore options with where clause
Optionaloptions: RestoreOptions & { where?: WhereOptions<any> }Optionaloptions: BulkCreateOptionsOptionaloptions: CountOptionsCOUNT() as window function - counts rows or non-null values
Optionaloptions: WindowFunctionOptions & { countField?: string }
Window function options (partitionBy, orderBy, windowFrame, countField)
The count value
Optionaloptions: AggregateOptionsAVG() as window function - calculates average in a partition
The field to average
Optionaloptions: WindowFunctionOptions
Window function options (partitionBy, orderBy, windowFrame)
The average value
Optionaloptions: AggregateOptionsMAX() as window function - returns maximum value in a partition
The field to find maximum
Optionaloptions: WindowFunctionOptions
Window function options (partitionBy, orderBy, windowFrame)
The maximum value
Optionaloptions: AggregateOptionsMIN() as window function - returns minimum value in a partition
The field to find minimum
Optionaloptions: WindowFunctionOptions
Window function options (partitionBy, orderBy, windowFrame)
The minimum value
Optionaloptions: AggregateOptions & { distinct?: boolean }SUM() as window function - sums values in a partition
The field to sum
Optionaloptions: WindowFunctionOptions
Window function options (partitionBy, orderBy, windowFrame)
The sum value
ROW_NUMBER() - Returns the row number within the partition
Window function options (partitionBy, orderBy, windowFrame)
The row number
RANK() - Returns the rank of the current row within the partition (with gaps)
Window function options (partitionBy, orderBy, windowFrame)
The rank value
DENSE_RANK() - Returns the rank of the current row within the partition (without gaps)
Window function options (partitionBy, orderBy, windowFrame)
The dense rank value
LAG() - Returns the value from the preceding row in the partition
The field to get value from
Optionaloptions: WindowFunctionOptions
Window function options (partitionBy, orderBy, windowFrame)
The value from the preceding row
LEAD() - Returns the value from the following row in the partition
The field to get value from
Optionaloptions: WindowFunctionOptions
Window function options (partitionBy, orderBy, windowFrame)
The value from the following row
FIRST_VALUE() - Returns the first value in the partition
The field to get first value from
Optionaloptions: WindowFunctionOptions
Window function options (partitionBy, orderBy, windowFrame)
The first value in the partition
LAST_VALUE() - Returns the last value in the partition
The field to get last value from
Optionaloptions: WindowFunctionOptions
Window function options (partitionBy, orderBy, windowFrame)
The last value in the partition
NTH_VALUE() - Returns the nth value in the partition
The field to get nth value from
The position (1-based)
Optionaloptions: WindowFunctionOptions
Window function options (partitionBy, orderBy, windowFrame)
The nth value in the partition
NTILE() - Distributes rows into n buckets
Number of buckets
Optionaloptions: WindowFunctionOptions
Window function options (partitionBy, orderBy)
The bucket number (1 to n)
PERCENT_RANK() - Returns the relative rank of a row (0 to 1)
Optionaloptions: WindowFunctionOptions
Window function options (partitionBy, orderBy)
The percent rank value
CUME_DIST() - Returns the cumulative distribution (0 to 1)
Optionaloptions: WindowFunctionOptions
Window function options (partitionBy, orderBy)
The cumulative distribution value
Generate a window function SQL expression for use in queries
The window function name (ROW_NUMBER, RANK, etc.)
Arguments to the window function
Window function options
Object with sql and values for the window function
Optionaloptions: UpsertOptionsFind a record by the given where clause, or create it if not found
Find options with where clause and defaults for creation
A tuple of [instance, created] where created is true if a new record was created
Find a record by the given where clause, or build (but not save) it if not found
Find options with where clause and defaults for building
A tuple of [instance, created] where created is true if a new instance was built
Find a record by the given where clause, or build (but not save) it if not found Alias for findOrBuild
Optionaloptions: TruncateOptionsOptionaloptions: DropOptionsRefresh a materialized view (PostgreSQL only)
Optionaloptions: RefreshOptions
Refresh options
Promise
Add a hook to the model
Name of the hook
Hook handler function
Add a named hook to the model
Name of the hook
Hook name identifier
Hook handler function
Check if a hook is registered
Name of the hook
True if hook is registered
Remove a hook from the model
Name of the hook
OptionalhookOrHookId: string | HookHandler
Optional hook or hook ID to remove
Create a view over this model.
Optionaldefinition: ModelViewDefinitionOptionaloptions: Record<string, unknown>Create a materialized view over this model.
Optionaldefinition: ModelViewDefinitionOptionaloptions: Record<string, unknown>Drop a view created from this model.
Optionaloptions: Record<string, unknown>
The static side of a model class — the finders, writers and association declarations, as opposed to an instance of it.