Skip to content

Table.get()

David Fahlander edited this page Nov 25, 2016 · 15 revisions

Syntax

table.get(primaryKey, callback);
table.get({keyPath1: value1, keyPath2: value2, ...}, callback);

Parameters

primaryKey Primary key of object to get
callback: Function function (item) { } optional
keyPath String identifying keyPath to filter on
value Value to match

Callback Parameters

item: Object Found item if any, otherwise undefined.

Return Value

Promise

Remarks

Fetches object of given primaryKey or criteras ({keyPath1: value1, keyPath2: value2}) 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.

Sample

let firstFriend = await db.friends.get(1);
let austinPowers = await db.friends.get({firstName: "Austin", lastName: "Powers"});
Clone this wiki locally