File tree Expand file tree Collapse file tree 2 files changed +37
-6
lines changed Expand file tree Collapse file tree 2 files changed +37
-6
lines changed Original file line number Diff line number Diff line change @@ -646,12 +646,29 @@ export class SimpleDbStore<
646646 range ?: IDBKeyRange
647647 ) : PersistencePromise < ValueType [ ] > {
648648 const cursor = this . cursor ( this . options ( indexOrRange , range ) ) ;
649- const results : ValueType [ ] = [ ] ;
650- return this . iterateCursor ( cursor , ( key , value ) => {
651- results . push ( value ) ;
652- } ) . next ( ( ) => {
653- return results ;
654- } ) ;
649+ // Use `getAll()` if the browser supports IndexedDB v3, as it is roughly
650+ // 20% faster. Unfortunately, getAll() does not support custom indices.
651+ if (
652+ typeof indexOrRange !== 'string' &&
653+ typeof this . store . getAll === 'function'
654+ ) {
655+ const request = this . store . getAll ( range || null ) ;
656+ return new PersistencePromise ( ( resolve , reject ) => {
657+ request . onerror = ( event : Event ) => {
658+ reject ( ( event . target as IDBRequest ) . error ! ) ;
659+ } ;
660+ request . onsuccess = ( event : Event ) => {
661+ resolve ( ( event . target as IDBRequest ) . result ) ;
662+ } ;
663+ } ) ;
664+ } else {
665+ const results : ValueType [ ] = [ ] ;
666+ return this . iterateCursor ( cursor , ( key , value ) => {
667+ results . push ( value ) ;
668+ } ) . next ( ( ) => {
669+ return results ;
670+ } ) ;
671+ }
655672 }
656673
657674 deleteAll ( ) : PersistencePromise < void > ;
Original file line number Diff line number Diff line change @@ -149,6 +149,20 @@ describe('SimpleDb', () => {
149149 } ) ;
150150 } ) ;
151151
152+ it ( 'can getAll' , async ( ) => {
153+ await runTransaction ( store => {
154+ return store
155+ . getAll ( 42 )
156+ . next ( user => {
157+ expect ( user ) . to . equal ( null ) ;
158+ return store . get ( 1 ) ;
159+ } )
160+ . next ( user => {
161+ expect ( user ) . to . deep . equal ( testData [ 1 ] ) ;
162+ } ) ;
163+ } ) ;
164+ } ) ;
165+
152166 it ( 'can put' , async ( ) => {
153167 await runTransaction ( store => {
154168 return store . put ( dummyUser ) ;
You can’t perform that action at this time.
0 commit comments