Created
November 3, 2015 20:00
-
-
Save efleming969/eee8c80441dd2c51c1f0 to your computer and use it in GitHub Desktop.
snippets for working with indexeddb object stores
This file contains hidden or 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
exports.getLowerBounds = function() | |
{ | |
var openReq = indexedDB.open( databaseName ) | |
openReq.onsuccess = function( e ) | |
{ | |
var idb = e.target.result | |
var transaction = idb.transaction( objectStoreName, "readonly" ) | |
var objectStore = transaction.objectStore( objectStoreName ) | |
var keyRangeValue = IDBKeyRange.lowerBound( 18 ) | |
var openCursorRequest = objectStore.openCursor( keyRangeValue ) | |
openCursorRequest.onsuccess = function( event ) | |
{ | |
var cursor = event.target.result | |
if ( cursor ) { | |
console.log( cursor.value ) | |
cursor.continue() | |
} else { | |
console.log( "Entries all displayed." ) | |
} | |
} | |
} | |
} | |
exports.getLatest = function() | |
{ | |
var openReq = indexedDB.open( databaseName ) | |
openReq.onsuccess = function( e ) | |
{ | |
var idb = e.target.result | |
var transaction = idb.transaction( objectStoreName, "readonly" ) | |
var objectStore = transaction.objectStore( objectStoreName ) | |
var openCursorRequest = objectStore.openCursor( null, "prev" ) | |
openCursorRequest.onsuccess = function( event ) | |
{ | |
var cursor = event.target.result | |
if ( cursor ) { | |
console.log( cursor.value ) | |
} else { | |
console.log( "Entries all displayed." ) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment