Skip to content

postgrelize / BulkCreateOptions

Type Alias: BulkCreateOptions<T> ​

BulkCreateOptions<T> = SaveOptions<T> & object

Defined in: src/model/bulk-options.ts:28

Options of bulkCreate.

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

Type Parameters ​

T ​

T = Values

Type Declaration ​

conflictAttributes? ​

optional conflictAttributes?: readonly (keyof T & string)[]

Conflict target attributes for updateOnDuplicate. Default: first unique key, else primary key.

conflictWhere? ​

optional conflictWhere?: WhereOptions<T>

Predicate of a partial unique index used as conflict target.

ignoreDuplicates? ​

optional ignoreDuplicates?: boolean

Add ON CONFLICT DO NOTHING, skipping rows that violate a unique constraint.

Default Value ​

ts
false

include? ​

optional include?: IncludeOption

Create associated rows from nested values (rows are inserted one by one).

individualHooks? ​

optional individualHooks?: boolean

Run per-instance create hooks (rows are then inserted one by one, like v6).

Default Value ​

ts
false

onConflict? ​

optional onConflict?: OnConflictOptions<T>

postgrelize extension

Advanced ON CONFLICT handling; cannot be combined with the options above. PostgreSQL extension.

unnest? ​

optional unnest?: boolean

postgrelize extension

Insert 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 Value ​

ts
false
@postgrelize

updateOnDuplicate? ​

optional updateOnDuplicate?: readonly (keyof T & string)[]

Attributes updated from the proposed row on conflict (DO UPDATE SET a = EXCLUDED.a).

See ​

Example ​

ts
const rows = [{ email: 'a@example.com', name: 'Ann' }];
await User.bulkCreate(rows, {
  updateOnDuplicate: ['name'],
  conflictAttributes: ['email'],
  transaction,
});
const opts: BulkCreateOptions<User> = { ignoreDuplicates: true };

Released under the MIT License.