DailyJS

Query IndexedDB Like MongoDB

Alex R. Young

Subscribe

@dailyjs

Facebook

Google+

APIs storage indexeddb

Query IndexedDB Like MongoDB

Posted by Alex R. Young on .
Featured

APIs storage indexeddb

Query IndexedDB Like MongoDB

Posted by Alex R. Young on .

Kent Safranski sent in Indexed, a library that wraps around IndexedDB with a friendly MongoDB-inspired API.

You can insert objects like this:

indexed('myDB').insert({  
  name: 'John Doe'
  email: 'jdoe@email.com'
}, function(err, data) {
  if (err) {
    console.error(err);
  } else {
    console.log(data);
  }
});

And fetch them again with find:

indexed('myDB').find({  
  _id: 28972387982
}, function(err, data) {
});

You can even use MongoDB-style operators:

indexed('myDB').find({  
  someNumber: { $gt : 25 }
}, function(err, data) {
});

You'll probably like this if you work with databases in Node. It's actually part of a larger project called Riggr, a framework based around RequireJS, Knockout and jQuery. Although I think indexed.js is cool enough that it should be a separate module, rather than being bundled in with Riggr.

Kent wrote a detailed blog post about indexed.js here: Indexed: Query IndexedDB Like Mongo.