Created
March 10, 2018 15:42
-
-
Save jloscos/72812eb6b293afa902f63b2e38043c46 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function searchValues<T>(db: IDBDatabase, storeName: string, search: any): Promise<T[]> { | |
const range = IDBKeyRange.lowerBound(search); | |
let results = []; | |
return new Promise<T[]>((resolve, reject) => { | |
const transaction = db.transaction(storeName, 'readonly'); | |
const store = transaction.objectStore(storeName); | |
const request = store.openCursor(range); | |
request.onsuccess = (event:any) => { | |
const cursor = event.target.result; | |
if (cursor) { | |
results.push(cursor.value); | |
cursor.continue(); | |
} else { | |
resolve(results); | |
} | |
}; | |
request.onerror = (event: any) => { | |
reject(event.error); | |
}; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment