-
-
Notifications
You must be signed in to change notification settings - Fork 646
Table.get()
David Fahlander edited this page Jan 27, 2017
·
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. |
If item was not found, returned promise will resolve with undefined. Otherwise it will resolve with the found value.
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.vehicles.where({owner: austin.id}).toArray(austinsVehicles => {
austin.vehicles = austinsVehicles;
return austin;
});
}).then (austinWithVehicles => {
//..
});
async function foo() {
let firstFriend = await db.friends.get(1);
console.log(firstFriend);
}
Dexie.js - minimalistic and bullet proof indexedDB library