Skip to content

qstarx/dexie-mongoify

 
 

Repository files navigation

Mongoify

Codeship CI status Deps

Mongoify is an addon for Dexie.js, IndexedDB wrapper.

Mongoify tries to provide MongoDB-like* query language and API, but uses promises instead of callbacks.

* MongoDB-like means that Mongoify tries to follow MongoDB where it makes sense, to simplify API and implementation. You are welcome to send PR that increases MongoDB compatibility.

API documentation

Examples:

You need to open database first:

var db = new Dexie('Database');
db.version(1).stores({ people: '++id, firstname, lastname, age' });
db.open();
// Thanks to Dexie, there is not need to wait for database to open,
// you can start working right away

Then you can start inserting objects:

var person = { firstname: 'John', lastname: 'Doe', age: 30 };
db.collection('people').insert(person).then(function() {

    // John is in db now :)

});
Querying database:

Get all objects:

db.collection('people').find({}).toArray().then(function(people) {
    // empty query returns all objects
});

Get objects by simple field match:

db.collection('people').find({ age: 30 }).toArray().then(function(people) {
    // people 30 years old
});

You can also use some of the MongoDB query operators:

db.collection('people').find({ age: { $gte: 23 } }).toArray().then(function(people) {
    // people that are 23 and more years old
});
Updating objects:
db.collection('people').update({ lastname: 'Doe' }, { age: 10 }).then(function(updatesCount) {
    // all Does are 10 years old now
});

Using update operators:

db.collection('people').findOne({ skills: { $in: ['html', 'javascript'] }  }, updates).then(function(person) {

    return db.collection('people').update(person, { $push: { skills: 'jquery' } });

}).then(function(updatesCount) {
    // person has jquery skills now
});

And more

License

MIT © Yury Solovyov

About

Dexie.js plugin with MongoDB-like API

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 99.4%
  • HTML 0.6%