Skip to content

WriteableTable.bulkAdd()

David Fahlander edited this page Mar 15, 2016 · 22 revisions

Since 1.3.0

Syntax

table.bulkAdd(items)

Parameters

items Array of objects to add

Return Value

Promise<>

**NOTE: Promise will succeed even when some of the operations fail.

Remarks

Add all given objects to the store.

If you have a large number of objects to add to the object store, bulkAdd() is a little faster than doing add() in a loop. The object store needs to have inbound keys, or have auto-incemented keys in order for bulkAdd to work - i.e. you're table schema must not start with an empty string.

var db = new Dexie("test");
db.version(1).stores({
    tableWithInboundKeys: "id,x,y,z", // ok
    tableWithAutoIncNonInbound: "++,x,y,x", // ok 
    tableWithoutInboundKeys: ",x,y,z" // not ok
});

Sample

var db = new Dexie("test");
db.version(1).stores({
    raindrops: 'id,position'
});
var drops = [];
for (var i=0;i<100000;++i) {
    drops.push({id: i, position: [Math.random(),Math.random(),Math.random()]}),
}
db.raindrops.bulkAdd(drops).then(function() {
    console.log("Done adding 100,000 raindrops all over the place");
});

See Also

WriteableTable.add()

Clone this wiki locally