Table.bulkPut()
Syntax
Parameters
items
Array of objects to put
keys
(optional)
Array of primary keys that corresponds to given items array
options (optional)
Since 3.0.0-rc.2:
{allKeys?: boolean}
If specifying {allKeys: true} the return value will be an array of resulting primary keys instead of just the primary key of the last add. If the table use inbound keys, the options can be given as the second argument. API will know if the second argument represents the options or the keys array by type inspection.
When to use the keys argument
If your primary key is inbound, you MUST NOT provide the
keys
argument.If primary key is non-inbound but auto-incremented,
keys
argument is optional.If primary key is non-inbound and non-auto-incremented,
keys
argument is compulsory.
Return Value
If options argument is omitted, or options is {allKeys: false}, the return value is a promise resolving with the resulting primary key of the object that was last in given array:
Promise<LastKey>
Since 3.0.0-rc.2: If options argument is provided in second or third argument with {allKeys: true}, the return value is a promise resulting with an array of resulting primary keys. The resulting array will have the same length as given array of objects to put. Every position in given items array will correspond to the same position in the resulting array.
Promise<Key[]>
Errors
If some operations fail, bulkPut()
will ignore those failures and return a rejected Promise with a Dexie.BulkError referencing the failures. If the caller does not catch the error, the transaction will abort. If the caller wants to ignore the failures, the bulkPut()
operations must be caught. NOTE: If you call bulkPut()
outside a transaction scope and an error occur on one of the operations, the successful operations will still be persisted to DB! If this is not desired, surround your call to bulkPut()
in a transaction and catch transaction's promise instead of the bulkPut()
operation.
Remarks
Add all given objects to the store.
If you have a large number of objects to add to the object store, bulkPut()
is faster than doing put()
in a loop. Mainly because it only has to get called back for the last onsuccess of all indexedDB requests.
Sample
See Also
Table.bulkUpdate()
Table.bulkGet()
Table.bulkAdd()
Table.bulkDelete()
Table.put()