mirror of
https://github.com/usebruno/bruno.git
synced 2024-12-27 00:59:12 +01:00
33 lines
911 B
JavaScript
33 lines
911 B
JavaScript
|
export const saveCollectionToIdb = (connection, domain, 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, domain) => {
|
||
|
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));
|
||
|
});
|
||
|
};
|