Git Product home page Git Product logo

dexie-mongoify's Introduction

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.