Table.bulkGet()

Since v3.0.0-alpha.8

Syntax

db.table.bulkGet(keys)

Parameters

keysArray of primary keys of the objects to retrieve

Return Value

Promise

Remarks

Request an array of keys and retrieve a Promise of an array of results. The resulting array will always have the same length as the given array of keys. Every position in given key array will correspond to the same position in the resulting array.

For those keys that do not exist in the database, undefined will be returned in their place.

Example


// Define DB
const db = new Dexie('foobardb');
db.version(1).stores({
  friends: 'id'
});

async function test() {
  // Add two friends:
  await db.friends.bulkAdd([{
    id: 1,
    name: "Foo"
  }, {
    id: 2,
    name: "Bar"
  }]);
  
  // Call bulkGet() to lookup values from given keys in the order of the requested array:
  const [foo, nonExisting, bar] = await db.friends.bulkGet([1, 777, 2]);
  assert (foo.name === "Foo");
  assert (bar.name === "Bar");
  assert (nonExisting === undefined);
}

test().then(()=>{
  console.log("success");
}).catch(error => {
  console.error(error);
});

See also

Table.bulkAdd()

Table.bulkPut()

Table.bulkDelete()

Table of Contents