Table.bulkUpdate()

Since v4.0.1-alpha.6

Syntax

await table.bulkUpdate([
  {
    key: key1,
    changes: {
      "keyPath1": newValue1,
      "keyPath2": newValue2,
      ...
    }
  },
  {
    key: key2,
    changes: {
      "keyPathA": newValueA,
      "keyPathB": newValueB,
      ...
    }
  },
  ...
]);

Parameters

key

Primary key of the object to update

changes

An object where each key is a property name or path and its value is the value to set

Remarks

This method is the bulk-version of Table.update() such that it accepts an array of keys/changes instead of a single key and changes-object.

This method will update objects with given keys using given update-specifications (changes) if the keys are found. If a key is not found, its corresponding changes wont be applied but the method will still succeed. The return value indicates how many keys were found (and updated).

The UpdateSpec provided in changes prop of each item can specify individual properties to be updated or deleted. Existing properties will be updated and non-existing properties will be added (if the row pointed out by the key exists). If the value provided is explicitly set to undefined, the property will be deleted.

Array properties follow the same keyPath pattern as object properties - using number as parts of the property name, such as tags.0, tags.1 etc, see sample below.

Sample (TypeScript)

Sample (Plain JS)

Return Value

The method returns the number of matching rows that were updated. A row is counted when a given key is found in the table, no matter if the update modifies the value to something that differs or not.

Errors

If some operations fail, bulkUpdate() will return a rejected Promise with a Dexie.BulkError referencing the failures.

See Also

Table.update()

Table.bulkDelete()

Table.bulkGet()

Table.bulkAdd()

Table.bulkDelete()