mirror of
https://github.com/getbible/app.git
synced 2024-12-21 23:48:53 +00:00
update utils
This commit is contained in:
parent
a68017a134
commit
f710d74f50
@ -55,58 +55,4 @@ export const querablePromise = function(promise) {
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
async function get(name, keyPath, transArray) {
|
||||
|
||||
let isValidInput = true
|
||||
let validInput = []
|
||||
|
||||
if(isObject(transArray) && has(transArray, ['name', 'keyPath'])){
|
||||
isValidInput = true
|
||||
validInput.push(transArray)
|
||||
}else if(isArray(transArray)){
|
||||
for (const o of transArray) {
|
||||
isValidInput = has(o, ['name', 'keyPath'])
|
||||
if(!isValidInput)
|
||||
break;
|
||||
}
|
||||
}else{
|
||||
isValidInput = false;
|
||||
}
|
||||
|
||||
let db = await this.getDb();
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
if(!isValidInput) reject("Invalid Input");
|
||||
|
||||
let trans = db.transaction([...validInput.map(v => v.name)],'readonly');
|
||||
trans.oncomplete = () => {
|
||||
resolve(output);
|
||||
};
|
||||
let output = []
|
||||
|
||||
for (const o of validInput) {
|
||||
let store = trans.objectStore(o.name);
|
||||
// let tr = {};
|
||||
|
||||
store.openCursor().onsuccess = e => {
|
||||
let cursor = e.target.result;
|
||||
if (cursor) {
|
||||
if(o.keyPath == cursor.value['abbreviation'])
|
||||
output.push(cursor.value)
|
||||
// tr = cursor.value
|
||||
cursor.continue();
|
||||
}
|
||||
};
|
||||
}
|
||||
trans.onerror = e => {
|
||||
reject(e)
|
||||
}
|
||||
trans.onabort = e => {
|
||||
reject(e)
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user