mirror of
https://github.com/usebruno/bruno.git
synced 2024-12-26 08:39:11 +01:00
41 lines
1.1 KiB
JavaScript
41 lines
1.1 KiB
JavaScript
import isArray from 'lodash/isArray';
|
|
|
|
export const saveCollectionToIdb = (connection, collection) => {
|
|
return new Promise((resolve, reject) => {
|
|
connection
|
|
.then((db) => {
|
|
let tx = db.transaction(`collection`, 'readwrite');
|
|
let collectionStore = tx.objectStore('collection');
|
|
|
|
if(isArray(collection)) {
|
|
for(let c of collection) {
|
|
collectionStore.put(c);
|
|
}
|
|
} else {
|
|
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));
|
|
});
|
|
}; |