Skip to content

Write options ​

Options of create, bulkCreate, update, destroy, restore, upsert, increment, instance save, and the PostgreSQL write statements: insert, insertFrom, ON CONFLICT, MERGE, UPDATE ... FROM, COPY.

Options marked postgrelize extension exist only in postgrelize; Sequelize v6 has no such option. This page is generated from the TypeScript declarations and their TSDoc, so it always matches the code.

BuildOptions ​

Options of Model.build (and the model constructor).

See also: Model.build.

ts
const opts: BuildOptions = { isNewRecord: false, raw: true };
const user = User.build({ id: 1, name: 'Ann' }, opts);
OptionTypeDescription
isNewRecordbooleanWhether the instance represents a row that does not exist yet; save() inserts when true, updates when false. Default: true.
rawbooleanSet values without setters and without change tracking. Default: false.
includeIncludeOptionBuild associated instances from nested values (Sequelize v6 nested creation).

CreateOptions ​

Options of create. Extends SaveOptions.

See also: Model.create.

ts
const post = await Post.create(
  { title: 'Hello', author: { name: 'Ann' } },
  { include: [{ association: 'author' }], transaction },
);
OptionTypeDescription
transactionTransactionTransaction to run in; null forces running outside the CLS transaction.
loggingfalse | LoggingFunctionSQL logger for this query, or false.
benchmarkbooleanPass query duration to the logger.
statementTimeout postgrelize extensionnumberstatement_timeout for this query only, in milliseconds (non-negative integer; 0 disables it). PostgreSQL cancels the statement with a DatabaseError (code 57014) when it runs longer. Outside a transaction the query runs in its own short transaction; inside one the previous timeout is restored afterwards. PostgreSQL extension.
retryReadonly<{ max?: number | undefined; match?: readonly RetryMatch[] | undefined; backoff…Retries this query when it fails, merged over the instance retry option (Sequelize v6). The connection acquisition is part of the retried work; a query that runs in a transaction is never retried.
useMaster postgrelize extensionbooleanForce the writer even for SELECTs when read replicas are configured. postgrelize extension.
replacementsReplacementsValues of ? (array) or :name (object) placeholders written in raw SQL inside the options (where: literal('"a" = :a'), attributes: [[literal(...), 'x']]), as in Sequelize v6. Every value is sent as a bound parameter, never concatenated into the SQL text; arrays expand to a comma separated list of parameters.
fieldsreadonly (0 extends 1 & T ? any : keyof T & string)[]Attributes to save; others are ignored. Default: all changed attributes. Mutable so hooks can adjust it, as in v6.
silentbooleanDo not update updatedAt. Default: false.
returningbooleanReturn all columns after insert/update; PostgreSQL always uses RETURNING, so this is accepted for v6 compatibility. Default: true.
hooksbooleanRun lifecycle hooks. Default: true.
validatebooleanRun validations. Default: true (false for bulkCreate).
overriding postgrelize extension"system" | "user"OVERRIDING SYSTEM VALUE / OVERRIDING USER VALUE for identity columns. PostgreSQL extension.
onConflict postgrelize extensionReadonly<{ target?: OnConflictTarget<T> | undefined; action: "nothing" | Readonly<{ upd…Advanced ON CONFLICT handling. PostgreSQL extension.
includeIncludeOptionCreate associated rows from nested values (Sequelize v6).

BulkCreateOptions ​

Options of bulkCreate. Extends SaveOptions. Rows are inserted with one INSERT unless individualHooks or include is set. Validation is off by default (unlike create).

See also: Model.bulkCreate, OnConflictOptions.

ts
const rows = [{ email: 'a@example.com', name: 'Ann' }];
await User.bulkCreate(rows, {
  updateOnDuplicate: ['name'],
  conflictAttributes: ['email'],
  transaction,
});
const opts: BulkCreateOptions<User> = { ignoreDuplicates: true };
OptionTypeDescription
transactionTransactionTransaction to run in; null forces running outside the CLS transaction.
loggingfalse | LoggingFunctionSQL logger for this query, or false.
benchmarkbooleanPass query duration to the logger.
statementTimeout postgrelize extensionnumberstatement_timeout for this query only, in milliseconds (non-negative integer; 0 disables it). PostgreSQL cancels the statement with a DatabaseError (code 57014) when it runs longer. Outside a transaction the query runs in its own short transaction; inside one the previous timeout is restored afterwards. PostgreSQL extension.
retryReadonly<{ max?: number | undefined; match?: readonly RetryMatch[] | undefined; backoff…Retries this query when it fails, merged over the instance retry option (Sequelize v6). The connection acquisition is part of the retried work; a query that runs in a transaction is never retried.
useMaster postgrelize extensionbooleanForce the writer even for SELECTs when read replicas are configured. postgrelize extension.
replacementsReplacementsValues of ? (array) or :name (object) placeholders written in raw SQL inside the options (where: literal('"a" = :a'), attributes: [[literal(...), 'x']]), as in Sequelize v6. Every value is sent as a bound parameter, never concatenated into the SQL text; arrays expand to a comma separated list of parameters.
fieldsreadonly (0 extends 1 & T ? any : keyof T & string)[]Attributes to save; others are ignored. Default: all changed attributes. Mutable so hooks can adjust it, as in v6.
silentbooleanDo not update updatedAt. Default: false.
returningbooleanReturn all columns after insert/update; PostgreSQL always uses RETURNING, so this is accepted for v6 compatibility. Default: true.
hooksbooleanRun lifecycle hooks. Default: true.
validatebooleanRun validations. Default: true (false for bulkCreate).
overriding postgrelize extension"system" | "user"OVERRIDING SYSTEM VALUE / OVERRIDING USER VALUE for identity columns. PostgreSQL extension.
unnest postgrelize extensionbooleanInsert with one array parameter per column (INSERT … SELECT * FROM unnest($1::type[], …)) instead of one parameter per cell, so batches are not capped by PostgreSQL's 65535 parameters. Every row must provide every column; ARRAY columns and conflict options are not supported. PostgreSQL extension. Default: false.
ignoreDuplicatesbooleanAdd ON CONFLICT DO NOTHING, skipping rows that violate a unique constraint. Default: false.
individualHooksbooleanRun per-instance create hooks (rows are then inserted one by one, like v6). Default: false.
includeIncludeOptionCreate associated rows from nested values (rows are inserted one by one).
updateOnDuplicatereadonly (keyof T & string)[]Attributes updated from the proposed row on conflict (DO UPDATE SET a = EXCLUDED.a).
conflictAttributesreadonly (keyof T & string)[]Conflict target attributes for updateOnDuplicate. Default: first unique key, else primary key.
conflictWhereWhereOptions<T>Predicate of a partial unique index used as conflict target.
onConflict postgrelize extensionReadonly<{ target?: OnConflictTarget<T> | undefined; action: "nothing" | Readonly<{ upd…Advanced ON CONFLICT handling; cannot be combined with the options above. PostgreSQL extension.

UpdateOptions ​

Options of static update. Extends BulkHookOptions. Updates updatedAt unless silent.

See also: Model.update.

ts
const [count] = await User.update(
  { active: false },
  { where: { lastLogin: { [Op.lt]: new Date('2020-01-01') } }, transaction },
);
const opts: UpdateOptions<Task> = { where: { done: false }, returning: true };
OptionTypeDescription
transactionTransactionTransaction to run in; null forces running outside the CLS transaction.
loggingfalse | LoggingFunctionSQL logger for this query, or false.
benchmarkbooleanPass query duration to the logger.
statementTimeout postgrelize extensionnumberstatement_timeout for this query only, in milliseconds (non-negative integer; 0 disables it). PostgreSQL cancels the statement with a DatabaseError (code 57014) when it runs longer. Outside a transaction the query runs in its own short transaction; inside one the previous timeout is restored afterwards. PostgreSQL extension.
retryReadonly<{ max?: number | undefined; match?: readonly RetryMatch[] | undefined; backoff…Retries this query when it fails, merged over the instance retry option (Sequelize v6). The connection acquisition is part of the retried work; a query that runs in a transaction is never retried.
useMaster postgrelize extensionbooleanForce the writer even for SELECTs when read replicas are configured. postgrelize extension.
replacementsReplacementsValues of ? (array) or :name (object) placeholders written in raw SQL inside the options (where: literal('"a" = :a'), attributes: [[literal(...), 'x']]), as in Sequelize v6. Every value is sent as a bound parameter, never concatenated into the SQL text; arrays expand to a comma separated list of parameters.
fieldsreadonly (keyof T & string)[]Attributes to update; others are ignored. Mutable so hooks can adjust it, as in v6.
whereWhereOptions<T>Rows to update.
silentbooleanDo not update updatedAt. Default: false.
returningbooleanReturn updated rows as the second element of the result.
returningOld postgrelize extensionbooleanWith returning: expose values before the update as instance.oldValues. PostgreSQL extension, needs PostgreSQL 18+.
validatebooleanValidate the new values. Default: true.
paranoidbooleanFor paranoid models: false also updates soft-deleted rows. Default: true.
from postgrelize extensionReadonly<Record<string, FromSourceOption>>Extra relations (UPDATE ... FROM), keyed by alias; reference them with col('alias.attr'). PostgreSQL extension.
hooksbooleanRun the bulk hooks (beforeBulkUpdate, beforeBulkDestroy, ...). Default: true.
individualHooksbooleanAlso run per-instance hooks; rows are loaded first, which costs an extra query. Default: false.

DestroyOptions ​

Options of static destroy. Extends BulkHookOptions. Paranoid models are soft-deleted (deletedAt set) unless force.

See also: Model.destroy.

ts
await Post.destroy({ where: { draft: true }, force: true });
const opts: DestroyOptions<Task> = { truncate: true, cascade: true, restartIdentity: true };
OptionTypeDescription
transactionTransactionTransaction to run in; null forces running outside the CLS transaction.
loggingfalse | LoggingFunctionSQL logger for this query, or false.
benchmarkbooleanPass query duration to the logger.
statementTimeout postgrelize extensionnumberstatement_timeout for this query only, in milliseconds (non-negative integer; 0 disables it). PostgreSQL cancels the statement with a DatabaseError (code 57014) when it runs longer. Outside a transaction the query runs in its own short transaction; inside one the previous timeout is restored afterwards. PostgreSQL extension.
retryReadonly<{ max?: number | undefined; match?: readonly RetryMatch[] | undefined; backoff…Retries this query when it fails, merged over the instance retry option (Sequelize v6). The connection acquisition is part of the retried work; a query that runs in a transaction is never retried.
useMaster postgrelize extensionbooleanForce the writer even for SELECTs when read replicas are configured. postgrelize extension.
replacementsReplacementsValues of ? (array) or :name (object) placeholders written in raw SQL inside the options (where: literal('"a" = :a'), attributes: [[literal(...), 'x']]), as in Sequelize v6. Every value is sent as a bound parameter, never concatenated into the SQL text; arrays expand to a comma separated list of parameters.
whereWhereOptions<T>Rows to delete.
limitnumberDelete at most this many rows.
truncatebooleanUse TRUNCATE instead of DELETE. Default: false.
cascadebooleanWith truncate: add CASCADE. Default: false.
restartIdentitybooleanWith truncate: add RESTART IDENTITY. Default: false.
returning postgrelize extensionbooleanReturn deleted rows instead of their count (DELETE ... RETURNING). PostgreSQL extension.
forcebooleanFor paranoid models: delete rows instead of setting deletedAt. Default: false.
using postgrelize extensionReadonly<Record<string, FromSourceOption>>Extra relations (DELETE ... USING), keyed by alias. PostgreSQL extension.
hooksbooleanRun the bulk hooks (beforeBulkUpdate, beforeBulkDestroy, ...). Default: true.
individualHooksbooleanAlso run per-instance hooks; rows are loaded first, which costs an extra query. Default: false.

RestoreOptions ​

Options of static restore, which clears deletedAt of soft-deleted rows of paranoid models.

See also: Model.restore.

ts
await Post.restore({ where: { authorId: 1 }, transaction });
const opts: RestoreOptions<Post> = { hooks: false };
OptionTypeDescription
transactionTransactionTransaction to run in; null forces running outside the CLS transaction.
loggingfalse | LoggingFunctionSQL logger for this query, or false.
benchmarkbooleanPass query duration to the logger.
statementTimeout postgrelize extensionnumberstatement_timeout for this query only, in milliseconds (non-negative integer; 0 disables it). PostgreSQL cancels the statement with a DatabaseError (code 57014) when it runs longer. Outside a transaction the query runs in its own short transaction; inside one the previous timeout is restored afterwards. PostgreSQL extension.
retryReadonly<{ max?: number | undefined; match?: readonly RetryMatch[] | undefined; backoff…Retries this query when it fails, merged over the instance retry option (Sequelize v6). The connection acquisition is part of the retried work; a query that runs in a transaction is never retried.
useMaster postgrelize extensionbooleanForce the writer even for SELECTs when read replicas are configured. postgrelize extension.
replacementsReplacementsValues of ? (array) or :name (object) placeholders written in raw SQL inside the options (where: literal('"a" = :a'), attributes: [[literal(...), 'x']]), as in Sequelize v6. Every value is sent as a bound parameter, never concatenated into the SQL text; arrays expand to a comma separated list of parameters.
whereWhereOptions<T>Rows to restore; all soft-deleted rows when omitted.
hooksbooleanRun the bulk hooks (beforeBulkUpdate, beforeBulkDestroy, ...). Default: true.
individualHooksbooleanAlso run per-instance hooks; rows are loaded first, which costs an extra query. Default: false.

UpsertOptions ​

Options of upsert. Extends SaveOptions. With onConflict the result of upsert becomes [instance, created].

See also: Model.upsert.

ts
const [user] = await User.upsert(
  { email: 'a@example.com', name: 'Ann' },
  { conflictFields: ['email'] },
);
OptionTypeDescription
transactionTransactionTransaction to run in; null forces running outside the CLS transaction.
loggingfalse | LoggingFunctionSQL logger for this query, or false.
benchmarkbooleanPass query duration to the logger.
statementTimeout postgrelize extensionnumberstatement_timeout for this query only, in milliseconds (non-negative integer; 0 disables it). PostgreSQL cancels the statement with a DatabaseError (code 57014) when it runs longer. Outside a transaction the query runs in its own short transaction; inside one the previous timeout is restored afterwards. PostgreSQL extension.
retryReadonly<{ max?: number | undefined; match?: readonly RetryMatch[] | undefined; backoff…Retries this query when it fails, merged over the instance retry option (Sequelize v6). The connection acquisition is part of the retried work; a query that runs in a transaction is never retried.
useMaster postgrelize extensionbooleanForce the writer even for SELECTs when read replicas are configured. postgrelize extension.
replacementsReplacementsValues of ? (array) or :name (object) placeholders written in raw SQL inside the options (where: literal('"a" = :a'), attributes: [[literal(...), 'x']]), as in Sequelize v6. Every value is sent as a bound parameter, never concatenated into the SQL text; arrays expand to a comma separated list of parameters.
fieldsreadonly (0 extends 1 & T ? any : keyof T & string)[]Attributes to save; others are ignored. Default: all changed attributes. Mutable so hooks can adjust it, as in v6.
silentbooleanDo not update updatedAt. Default: false.
returningbooleanReturn all columns after insert/update; PostgreSQL always uses RETURNING, so this is accepted for v6 compatibility. Default: true.
hooksbooleanRun lifecycle hooks. Default: true.
validatebooleanRun validations. Default: true (false for bulkCreate).
overriding postgrelize extension"system" | "user"OVERRIDING SYSTEM VALUE / OVERRIDING USER VALUE for identity columns. PostgreSQL extension. OVERRIDING SYSTEM VALUE / OVERRIDING USER VALUE for identity columns.
conflictFieldsreadonly string[]Conflict target columns. Default: unique key containing a given attribute, else the primary key.
onConflict postgrelize extensionReadonly<{ target?: OnConflictTarget<T> | undefined; action: "nothing" | Readonly<{ upd…Advanced ON CONFLICT handling; the result becomes [instance, created]. PostgreSQL extension.

SaveOptions ​

Options of create and instance save. Runs beforeSave / beforeCreate / beforeUpdate hooks (and their after counterparts) unless hooks is false.

See also: Model.create.

ts
const opts: SaveOptions<User> = { fields: ['name', 'email'], validate: true, transaction };
await user.save(opts);
OptionTypeDescription
transactionTransactionTransaction to run in; null forces running outside the CLS transaction.
loggingfalse | LoggingFunctionSQL logger for this query, or false.
benchmarkbooleanPass query duration to the logger.
statementTimeout postgrelize extensionnumberstatement_timeout for this query only, in milliseconds (non-negative integer; 0 disables it). PostgreSQL cancels the statement with a DatabaseError (code 57014) when it runs longer. Outside a transaction the query runs in its own short transaction; inside one the previous timeout is restored afterwards. PostgreSQL extension.
retryReadonly<{ max?: number | undefined; match?: readonly RetryMatch[] | undefined; backoff…Retries this query when it fails, merged over the instance retry option (Sequelize v6). The connection acquisition is part of the retried work; a query that runs in a transaction is never retried.
useMaster postgrelize extensionbooleanForce the writer even for SELECTs when read replicas are configured. postgrelize extension.
replacementsReplacementsValues of ? (array) or :name (object) placeholders written in raw SQL inside the options (where: literal('"a" = :a'), attributes: [[literal(...), 'x']]), as in Sequelize v6. Every value is sent as a bound parameter, never concatenated into the SQL text; arrays expand to a comma separated list of parameters.
fieldsreadonly (0 extends 1 & T ? any : keyof T & string)[]Attributes to save; others are ignored. Default: all changed attributes. Mutable so hooks can adjust it, as in v6.
silentbooleanDo not update updatedAt. Default: false.
returningbooleanReturn all columns after insert/update; PostgreSQL always uses RETURNING, so this is accepted for v6 compatibility. Default: true.
hooksbooleanRun lifecycle hooks. Default: true.
validatebooleanRun validations. Default: true (false for bulkCreate).
overriding postgrelize extension"system" | "user"OVERRIDING SYSTEM VALUE / OVERRIDING USER VALUE for identity columns. PostgreSQL extension.

InstanceUpdateOptions ​

Options of the instance updates that association accessors run (Sequelize v6 InstanceUpdateOptions): the SaveOptions.

ts
const options: InstanceUpdateOptions<User> = { fields: ['name'], transaction };
await user.update({ name: 'Ann' }, options);
OptionTypeDescription
transactionTransactionTransaction to run in; null forces running outside the CLS transaction.
loggingfalse | LoggingFunctionSQL logger for this query, or false.
benchmarkbooleanPass query duration to the logger.
statementTimeout postgrelize extensionnumberstatement_timeout for this query only, in milliseconds (non-negative integer; 0 disables it). PostgreSQL cancels the statement with a DatabaseError (code 57014) when it runs longer. Outside a transaction the query runs in its own short transaction; inside one the previous timeout is restored afterwards. PostgreSQL extension.
retryReadonly<{ max?: number | undefined; match?: readonly RetryMatch[] | undefined; backoff…Retries this query when it fails, merged over the instance retry option (Sequelize v6). The connection acquisition is part of the retried work; a query that runs in a transaction is never retried.
useMaster postgrelize extensionbooleanForce the writer even for SELECTs when read replicas are configured. postgrelize extension.
replacementsReplacementsValues of ? (array) or :name (object) placeholders written in raw SQL inside the options (where: literal('"a" = :a'), attributes: [[literal(...), 'x']]), as in Sequelize v6. Every value is sent as a bound parameter, never concatenated into the SQL text; arrays expand to a comma separated list of parameters.
fieldsreadonly (0 extends 1 & T ? any : keyof T & string)[]Attributes to save; others are ignored. Default: all changed attributes. Mutable so hooks can adjust it, as in v6.
silentbooleanDo not update updatedAt. Default: false.
returningbooleanReturn all columns after insert/update; PostgreSQL always uses RETURNING, so this is accepted for v6 compatibility. Default: true.
hooksbooleanRun lifecycle hooks. Default: true.
validatebooleanRun validations. Default: true (false for bulkCreate).
overriding postgrelize extension"system" | "user"OVERRIDING SYSTEM VALUE / OVERRIDING USER VALUE for identity columns. PostgreSQL extension.

InstanceDestroyOptions ​

Options of instance destroy.

See also: Model.destroy.

ts
await post.destroy({ force: true, transaction });
const opts: InstanceDestroyOptions = { hooks: false };
OptionTypeDescription
transactionTransactionTransaction to run in; null forces running outside the CLS transaction.
loggingfalse | LoggingFunctionSQL logger for this query, or false.
benchmarkbooleanPass query duration to the logger.
statementTimeout postgrelize extensionnumberstatement_timeout for this query only, in milliseconds (non-negative integer; 0 disables it). PostgreSQL cancels the statement with a DatabaseError (code 57014) when it runs longer. Outside a transaction the query runs in its own short transaction; inside one the previous timeout is restored afterwards. PostgreSQL extension.
retryReadonly<{ max?: number | undefined; match?: readonly RetryMatch[] | undefined; backoff…Retries this query when it fails, merged over the instance retry option (Sequelize v6). The connection acquisition is part of the retried work; a query that runs in a transaction is never retried.
useMaster postgrelize extensionbooleanForce the writer even for SELECTs when read replicas are configured. postgrelize extension.
replacementsReplacementsValues of ? (array) or :name (object) placeholders written in raw SQL inside the options (where: literal('"a" = :a'), attributes: [[literal(...), 'x']]), as in Sequelize v6. Every value is sent as a bound parameter, never concatenated into the SQL text; arrays expand to a comma separated list of parameters.
forcebooleanFor paranoid models: delete the row instead of setting deletedAt. Default: false.
hooksbooleanRun beforeDestroy / afterDestroy hooks. Default: true.

IncrementOptions ​

Options of increment and decrement. Runs one UPDATE ... SET col = col + n and updates updatedAt unless silent.

See also: Model.increment.

ts
await Product.increment('stock', { by: 5, where: { id: 1 } });
const opts: IncrementOptions<Product> = { by: 2, silent: true, transaction };
const product = await Product.findByPk(1);
await product!.decrement('stock', opts);
OptionTypeDescription
transactionTransactionTransaction to run in; null forces running outside the CLS transaction.
loggingfalse | LoggingFunctionSQL logger for this query, or false.
benchmarkbooleanPass query duration to the logger.
statementTimeout postgrelize extensionnumberstatement_timeout for this query only, in milliseconds (non-negative integer; 0 disables it). PostgreSQL cancels the statement with a DatabaseError (code 57014) when it runs longer. Outside a transaction the query runs in its own short transaction; inside one the previous timeout is restored afterwards. PostgreSQL extension.
retryReadonly<{ max?: number | undefined; match?: readonly RetryMatch[] | undefined; backoff…Retries this query when it fails, merged over the instance retry option (Sequelize v6). The connection acquisition is part of the retried work; a query that runs in a transaction is never retried.
useMaster postgrelize extensionbooleanForce the writer even for SELECTs when read replicas are configured. postgrelize extension.
replacementsReplacementsValues of ? (array) or :name (object) placeholders written in raw SQL inside the options (where: literal('"a" = :a'), attributes: [[literal(...), 'x']]), as in Sequelize v6. Every value is sent as a bound parameter, never concatenated into the SQL text; arrays expand to a comma separated list of parameters.
whereWhereOptions<T>Rows to change; required for the static form, ignored on instances.
bynumberAmount to add (increment) or subtract (decrement). Default: 1.
silentbooleanDo not update updatedAt. Default: false.

InsertOptions postgrelize extension ​

Options of Model.insert. PostgreSQL extension. Rows are inserted with a single INSERT and no per-row save hooks; only the bulk-create hooks run.

See also: Model.insert.

ts
const opts: InsertOptions<User> = {
  onConflict: { target: ['email'], action: 'nothing' },
  hooks: false,
};
const rows = await User.insert([{ email: 'a@example.com' }], opts);
OptionTypeDescription
transactionTransactionTransaction to run in; null forces running outside the CLS transaction.
loggingfalse | LoggingFunctionSQL logger for this query, or false.
benchmarkbooleanPass query duration to the logger.
statementTimeout postgrelize extensionnumberstatement_timeout for this query only, in milliseconds (non-negative integer; 0 disables it). PostgreSQL cancels the statement with a DatabaseError (code 57014) when it runs longer. Outside a transaction the query runs in its own short transaction; inside one the previous timeout is restored afterwards. PostgreSQL extension.
retryReadonly<{ max?: number | undefined; match?: readonly RetryMatch[] | undefined; backoff…Retries this query when it fails, merged over the instance retry option (Sequelize v6). The connection acquisition is part of the retried work; a query that runs in a transaction is never retried.
useMaster postgrelize extensionbooleanForce the writer even for SELECTs when read replicas are configured. postgrelize extension.
replacementsReplacementsValues of ? (array) or :name (object) placeholders written in raw SQL inside the options (where: literal('"a" = :a'), attributes: [[literal(...), 'x']]), as in Sequelize v6. Every value is sent as a bound parameter, never concatenated into the SQL text; arrays expand to a comma separated list of parameters.
fieldsreadonly (keyof T & string)[]Attributes to insert; others are ignored. Default: all given attributes.
onConflictReadonly<{ target?: OnConflictTarget<T> | undefined; action: "nothing" | Readonly<{ upd…Advanced ON CONFLICT handling.
hooksbooleanRun beforeBulkCreate / afterBulkCreate hooks. Default: true.
validatebooleanValidate rows before inserting. Default: false.
overriding"system" | "user"OVERRIDING SYSTEM VALUE / OVERRIDING USER VALUE for identity columns.
returningOld postgrelize extensionbooleanReturn the pre-statement row values as instance.oldValues. PostgreSQL extension, needs PostgreSQL 18+.

InsertFromOptions postgrelize extension ​

Options of Model.insertFrom, which inserts the result of a subquery (INSERT ... SELECT). PostgreSQL extension.

See also: Model.insertFrom.

ts
const opts: InsertFromOptions<Task> = {
  columns: ['title', 'projectId'],
  onConflict: { action: 'nothing' },
};
OptionTypeDescription
transactionTransactionTransaction to run in; null forces running outside the CLS transaction.
loggingfalse | LoggingFunctionSQL logger for this query, or false.
benchmarkbooleanPass query duration to the logger.
statementTimeout postgrelize extensionnumberstatement_timeout for this query only, in milliseconds (non-negative integer; 0 disables it). PostgreSQL cancels the statement with a DatabaseError (code 57014) when it runs longer. Outside a transaction the query runs in its own short transaction; inside one the previous timeout is restored afterwards. PostgreSQL extension.
retryReadonly<{ max?: number | undefined; match?: readonly RetryMatch[] | undefined; backoff…Retries this query when it fails, merged over the instance retry option (Sequelize v6). The connection acquisition is part of the retried work; a query that runs in a transaction is never retried.
useMaster postgrelize extensionbooleanForce the writer even for SELECTs when read replicas are configured. postgrelize extension.
replacementsReplacementsValues of ? (array) or :name (object) placeholders written in raw SQL inside the options (where: literal('"a" = :a'), attributes: [[literal(...), 'x']]), as in Sequelize v6. Every value is sent as a bound parameter, never concatenated into the SQL text; arrays expand to a comma separated list of parameters.
columnsreadonly (keyof T & string)[]Target attributes, in the order of the subquery columns.
onConflictReadonly<{ target?: OnConflictTarget<T> | undefined; action: "nothing" | Readonly<{ upd…Advanced ON CONFLICT handling.
returningOldbooleanReturn the pre-statement row values as instance.oldValues. PostgreSQL 18+.

OnConflictOptions postgrelize extension ​

Advanced INSERT ... ON CONFLICT specification. PostgreSQL extension.

ts
const rows = [{ tenantId: 1, key: 'views', hits: 1, version: 2 }];
await Product.bulkCreate(rows, {
  onConflict: {
    target: ['tenantId', 'key'],
    action: {
      update: { hits: literal('"Product"."hits" + EXCLUDED."hits"'), updatedAt: fn('now') },
      where: { version: { [Op.lt]: excluded('version') } },
    },
  },
});
OptionTypeDescription
targetOnConflictTarget<T>Unique index or constraint to arbitrate on. Required for update.
action"nothing" | Readonly<{ update: OnConflictUpdate<T>; where?: WhereOptions<T> | undefined…'nothing' to skip conflicting rows, or an update.

MergeOptions postgrelize extension ​

Options of Model.merge, which runs a MERGE statement. PostgreSQL extension. PostgreSQL 15+ (RETURNING: 17+). Rows of the model table are the target; source rows or a subquery are the source.

See also: Model.merge.

ts
const opts: MergeOptions<Product> = {
  source: [{ sku: 'a1', price: 10 }],
  on: { sku: col('source.sku') },
  whenMatched: { update: { price: col('source.price') } },
  whenNotMatched: { insert: true },
};
OptionTypeDescription
sourceSubquery | readonly Readonly<Record<string, unknown>>[]Source rows (plain objects) or a subquery.
asstringAlias of the source relation. Default: 'source'.
on{}Join condition between target (model alias) and source (col('source.attr')).
whenMatchedMergeMatchedAction<T> | readonly MergeMatchedAction<T>[]Actions for matched rows, applied in order.
whenNotMatchedMergeInsertAction<T> | readonly MergeInsertAction<T>[]Actions for source rows without a target row.
whenNotMatchedBySourceMergeMatchedAction<T> | readonly MergeMatchedAction<T>[]Actions for target rows without a source row (PostgreSQL 17+).

UpdateStatementOptions postgrelize extension ​

Options of Model.updateStatement(). PostgreSQL extension.

ts
const options: UpdateStatementOptions<Task> = { where: { id: 1 }, returning: true, silent: true };
OptionTypeDescription
whereWhereOptions<T>Rows to change; all rows when omitted. The default scope applies.
returningbooleanAdd RETURNING with all columns, so that the CTE can be read.
silentbooleanLeave updatedAt unchanged.

WriteStatementOptions ​

Options of Model.deleteStatement() and Model.updateStatement().

ts
const options: WriteStatementOptions<Task> = { where: { done: true }, returning: true };
OptionTypeDescription
whereWhereOptions<T>Rows to change; all rows when omitted. The default scope applies.
returningbooleanAdd RETURNING with all columns, so that the CTE can be read.

CopyFromOptions postgrelize extension ​

Options of Model.copyFrom, which loads rows with COPY ... FROM STDIN. PostgreSQL extension.

See also: Model.copyFrom.

ts
const opts: CopyFromOptions<User> = { columns: ['name', 'email'], transaction };
await User.copyFrom([{ name: 'Ann', email: 'a@example.com' }], opts);
OptionTypeDescription
transactionTransactionTransaction to run in; null forces running outside the CLS transaction.
loggingfalse | LoggingFunctionSQL logger for this query, or false.
benchmarkbooleanPass query duration to the logger.
statementTimeout postgrelize extensionnumberstatement_timeout for this query only, in milliseconds (non-negative integer; 0 disables it). PostgreSQL cancels the statement with a DatabaseError (code 57014) when it runs longer. Outside a transaction the query runs in its own short transaction; inside one the previous timeout is restored afterwards. PostgreSQL extension.
retryReadonly<{ max?: number | undefined; match?: readonly RetryMatch[] | undefined; backoff…Retries this query when it fails, merged over the instance retry option (Sequelize v6). The connection acquisition is part of the retried work; a query that runs in a transaction is never retried.
useMaster postgrelize extensionbooleanForce the writer even for SELECTs when read replicas are configured. postgrelize extension.
replacementsReplacementsValues of ? (array) or :name (object) placeholders written in raw SQL inside the options (where: literal('"a" = :a'), attributes: [[literal(...), 'x']]), as in Sequelize v6. Every value is sent as a bound parameter, never concatenated into the SQL text; arrays expand to a comma separated list of parameters.
columnsreadonly (keyof T & string)[]Attributes to copy, in row order; default: keys of the first row of an array source.

CopyToOptions postgrelize extension ​

Options of Model.copyTo: a finder query that selects the exported rows plus the output format. PostgreSQL extension.

See also: Model.copyTo.

ts
const opts: CopyToOptions<User> = { where: { active: true }, order: [['id', 'ASC']], format: 'csv', header: true };
OptionTypeDescription
transactionTransactionTransaction to run in; null forces running outside the CLS transaction.
loggingfalse | LoggingFunctionSQL logger for this query, or false.
benchmarkbooleanPass query duration to the logger.
statementTimeout postgrelize extensionnumberstatement_timeout for this query only, in milliseconds (non-negative integer; 0 disables it). PostgreSQL cancels the statement with a DatabaseError (code 57014) when it runs longer. Outside a transaction the query runs in its own short transaction; inside one the previous timeout is restored afterwards. PostgreSQL extension.
retryReadonly<{ max?: number | undefined; match?: readonly RetryMatch[] | undefined; backoff…Retries this query when it fails, merged over the instance retry option (Sequelize v6). The connection acquisition is part of the retried work; a query that runs in a transaction is never retried.
useMaster postgrelize extensionbooleanForce the writer even for SELECTs when read replicas are configured. postgrelize extension.
replacementsReplacementsValues of ? (array) or :name (object) placeholders written in raw SQL inside the options (where: literal('"a" = :a'), attributes: [[literal(...), 'x']]), as in Sequelize v6. Every value is sent as a bound parameter, never concatenated into the SQL text; arrays expand to a comma separated list of parameters.
attributesFindAttributeOptionsSelected attributes. All attributes when omitted.
orderOrder | readonly unknown[]Sort order: attribute names, [attribute, 'ASC' | 'DESC'] pairs or expressions.
group{}GROUP BY attributes or expressions.
having{}HAVING condition.
limitnumberMaximum number of rows; null or undefined for no limit.
offsetnumberNumber of rows to skip; null or undefined to skip none.
lockLockOptionRow lock (FOR UPDATE etc.); requires a transaction.
skipLockedbooleanAdd SKIP LOCKED to the row lock; only with lock.
noWait postgrelize extensionbooleanAdd NOWAIT to the row lock so the query fails instead of waiting; only with lock. PostgreSQL extension.
distinctOn postgrelize extensionreadonly unknown[]SELECT DISTINCT ON (...): attributes or expressions. PostgreSQL extension.
withTies postgrelize extensionbooleanFETCH FIRST limit ROWS WITH TIES instead of LIMIT: also returns the rows that tie with the last one on the order columns. Needs limit and order. PostgreSQL extension.
sample postgrelize extensionReadonly<{ method: "BERNOULLI" | "SYSTEM"; percent: number; seed?: number | undefined; }>Read only a random sample of the model table (TABLESAMPLE). PostgreSQL extension.
whereWhereOptions<T>Filter rows; see WhereOptions. All rows when omitted.
rawbooleanReturn plain row objects instead of model instances. Default: false.
nestbooleanWith raw, build nested objects from dotted keys such as 'posts.title'. Default: false.
plainbooleanReturn a single row instead of an array (set internally by findOne). Default: false.
rejectOnEmptyboolean | ErrorThrow EmptyResultError (or the given Error) when no row is found. Default: false.
paranoidbooleanFor paranoid models: false includes soft-deleted rows. Default: true.
hooksbooleanRun beforeFind / afterFind hooks. Default: true.
includeIncludeOptionEager-load associations through JOINs (or separate queries for separate includes).
subQuerybooleanfalse disables the sub-query used for limit combined with multi-row includes.
tableAsstringAlias of the main table in FROM instead of the model name, so literals and col('alias.x') can refer to it (a v6 internal option that v6's typings omit). Ignored when include is set.
with postgrelize extensionReadonly<Record<string, Subquery | Readonly<{ query: Subquery | WriteStatement; recursi…Common table expressions (WITH [RECURSIVE] ...). PostgreSQL extension.
source postgrelize extensionstring | SubqueryRead model rows from this relation instead of the model table: a CTE or table name, or a subquery such as a set operation (a.union(b)), aliased with the model name. Columns are named like the attributes. PostgreSQL extension.
from postgrelize extensionReadonly<Record<string, FromSourceOption>>Extra relations (FROM "Model", "alias"), keyed by alias; correlate them in where. PostgreSQL extension.
format"text" | "csv" | "binary"Output format. Default: 'text'.
headerbooleanEmit a header line (csv). Default: false.
delimiterstringSingle-character field delimiter. Default: tab for text, comma for csv.
nullStringstringString written for NULL values. Default: \N for text, empty for csv.
quotestringSingle-character quote (csv). Default: ".

CopyToFormatOptions postgrelize extension ​

Output format options of Model.copyTo (COPY ... TO STDOUT). PostgreSQL extension.

ts
const format: CopyToFormatOptions = { format: 'csv', header: true, delimiter: ';', nullString: '' };
OptionTypeDescription
format"text" | "csv" | "binary"Output format. Default: 'text'.
headerbooleanEmit a header line (csv). Default: false.
delimiterstringSingle-character field delimiter. Default: tab for text, comma for csv.
nullStringstringString written for NULL values. Default: \N for text, empty for csv.
quotestringSingle-character quote (csv). Default: ".

BulkHookOptions ​

Hook switches shared by bulk update, destroy and restore.

ts
const opts: BulkHookOptions = { hooks: true, individualHooks: true };
await User.destroy({ where: { active: false }, ...opts });
OptionTypeDescription
hooksbooleanRun the bulk hooks (beforeBulkUpdate, beforeBulkDestroy, ...). Default: true.
individualHooksbooleanAlso run per-instance hooks; rows are loaded first, which costs an extra query. Default: false.

Released under the MIT License.