src/store/indexeddb-local-backend.js
function selectQuery(store, keyRange, resultMapper) {
    const query = store.openCursor(keyRange);
    return new Promise((resolve, reject) => {
        const results = [];
        query.onerror = (event) => {
            reject(new Error("Query failed: " + event.target.errorCode));
        };
        // collect results
        query.onsuccess = (event) => {
            const cursor = event.target.result;
            if (!cursor) {
                resolve(results);
                return; // end of results
            }
            results.push(resultMapper(cursor));
            cursor.continue();
        };
    });
}
function selectQuery(store, keyRange, resultMapper) {
    const query = store.openCursor(keyRange);
    return new Promise((resolve, reject) => {
        const results = [];
        query.onerror = (event) => {
            reject(new Error("Query failed: " + event.target.errorCode));
        };
        // collect results
        query.onsuccess = (event) => {
            const cursor = event.target.result;
            if (!cursor) {
                resolve(results);
                return; // end of results
            }
            results.push(resultMapper(cursor));
            cursor.continue();
        };
    });
}
function selectQuery ( store , keyRange , resultMapper ) { const query = store . openCursor ( keyRange ) ; return new Promise ( ( resolve , reject ) => { const results = [ ] ; query . onerror = ( event ) => { reject ( new Error ( "Query failed: " + event . target . errorCode ) ) ; } ; // collect results query . onsuccess = ( event ) => { const cursor = event . target . result ; if ( ! cursor ) { resolve ( results ) ; return ; // end of results } results . push ( resultMapper ( cursor ) ) ; cursor . continue ( ) ; } ; } ) ; }
Helper method to collect results from a Cursor and promiseify it.
@param {ObjectStore|Index} store The store to perform openCursor on.
@param {IDBKeyRange=} keyRange Optional key range to apply on the cursor.
@param {Function} resultMapper A function which is repeatedly called with a
Cursor.
Return the data you want to keep.
@return {Promise<T[]>} Resolves to an array of whatever you returned from
resultMapper.
Helper method to collect results from a Cursor and promiseify it .