Skip to content

Instantly share code, notes, and snippets.

@efleming969
Created November 3, 2015 20:00
Show Gist options
  • Save efleming969/eee8c80441dd2c51c1f0 to your computer and use it in GitHub Desktop.
Save efleming969/eee8c80441dd2c51c1f0 to your computer and use it in GitHub Desktop.
snippets for working with indexeddb object stores
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