Add Database.getCount
function
This commit is contained in:
parent
1f8556b049
commit
0fdc1140dd
1 changed files with 17 additions and 0 deletions
|
@ -4,6 +4,9 @@
|
|||
// and using promises. Revisit use of `idb` dependency as it might cover
|
||||
// this functionality.
|
||||
|
||||
const isObject = require('lodash/isObject');
|
||||
|
||||
|
||||
exports.open = (name, version) => {
|
||||
const request = indexedDB.open(name, version);
|
||||
return new Promise((resolve, reject) => {
|
||||
|
@ -37,3 +40,17 @@ exports.getVersion = async (name) => {
|
|||
connection.close();
|
||||
return version;
|
||||
};
|
||||
|
||||
exports.getCount = async ({ store } = {}) => {
|
||||
if (!isObject(store)) {
|
||||
throw new TypeError('"store" is required');
|
||||
}
|
||||
|
||||
const request = store.count();
|
||||
return new Promise((resolve, reject) => {
|
||||
request.onerror = event =>
|
||||
reject(event.target.error);
|
||||
request.onsuccess = event =>
|
||||
resolve(event.target.result);
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue