-
-
Notifications
You must be signed in to change notification settings - Fork 652
Table.get()
David Fahlander edited this page Nov 25, 2016
·
15 revisions
// Dexie 1.x and 2.x:
table.get(primaryKey, callback);
// Dexie 2.x only:
table.get({keyPath1: value1, keyPath2: value2, ...}, callback);
primaryKey | Primary key of object to get | |
callback: Function | function (item) { } |
optional |
{keyPath1: value1, keyPath2: value2, ...} | Criterias to filter |
item: Object | Found item if any, otherwise undefined. |
Fetches object of given primaryKey or where given criteras ({keyPath1: value1, keyPath2: value2}) are fulfilled and returns the first matching result.
If callback is omitted and operation succeeds, returned Promise will resolve with the result of the operation, calling any Promise.then() callback.
If callback is specified and operation succeeds, given callback will be called and the returned Promise will resolve with the return value of given callback.
If operation fails, returned promise will reject, calling any Promise.catch() callback.
db.friends.get(1, function (firstFriend) {
alert ("Friend with id 1: " + firstFriend.name);
});
db.friends.get(1).then (function (firstFriend) {
alert ("Friend with id 1: " + firstFriend.name);
});
db.friends.get({firstName: "Austin", lastName: "Powers"}, austin => {
return db.pets.where({owner: austin.id}).toArray(austinsPets => {
austin.pets = austinsPets;
return austin;
});
}).then (austinWithPets => {
//..
});
let firstFriend = await db.friends.get(1);
let austinPowers = await db.friends.get({firstName: "Austin", lastName: "Powers"});
Dexie.js - minimalistic and bullet proof indexedDB library