bruno/renderer/providers/Store/idb.js
2022-03-13 17:43:21 +05:30

33 lines
895 B
JavaScript

export const saveCollectionToIdb = (connection, collection) => {
return new Promise((resolve, reject) => {
connection
.then((db) => {
let tx = db.transaction(`collection`, 'readwrite');
let collectionStore = tx.objectStore('collection');
collectionStore.put(collection);
resolve();
})
.catch((err) => reject(err));
});
};
export const getCollectionsFromIdb = (connection) => {
return new Promise((resolve, reject) => {
connection
.then((db) => {
let tx = db.transaction('collection');
let collectionStore = tx.objectStore('collection');
return collectionStore.getAll();
})
.then((collections) => {
if(!Array.isArray(collections)) {
return new Error('IDB Corrupted');
}
return resolve(collections);
})
.catch((err) => reject(err));
});
};