0.5.1 • Published 9 years ago

mpill v0.5.1

Weekly downloads
1
License
MIT
Repository
github
Last release
9 years ago

MPill

Coding apps without to be worried about data models.

Single model instance

var MPill = require('mpill').MPill;
var url = 'mongodb://127.0.0.1/mpill';
users = new MPill('users', url);

Multiple models at once

models.js

var MPill = require('../mpill.js').MPill;

var colls = ['users','groups','roles','tasks'];
var url   = 'mongodb://127.0.0.1/mydb';

// exports each collection
for(var i in colls){
	module.exports[colls[i]] = new MPill(colls[i], url);
}

userController.js (let's said this is for express route)

var models = require('./models');
var Users = {};

Users.List = function(req, res){
  models.users.FindOne({'email': 'rrunner@acme.co'}, function(err, rrunner){
    if(err){ return res.status(500); }
    var query = { user_id: rrunner._id, label: 'open' };
      models.tasks.Find(query, function(err, toDo){
        if(err){ return res.status(500); }
        res.json({
          user: rrunner,
          tasks: toDo
        });
      });
    });
};
...
module.exports.Users = Users;

API reference

'Generic methods'
model.Connect(cb)
model.DropDB(cb)

'Common methods'
model.Insert(doc, cb)
model.Update(query, doc, concern, cb)
model.Remove(query, cb)
model.Find(query, cb, project, options, limit, sort)
model.FindOne(query, cb)
model.CreateIndex(query, cb)
model.DropCollection(query, cb)
model.DropIndex(query, cb)
model.CreateCollection(cb)
model.Count(query, cb)
model.Aggregate(query, cb)

'Special methods'
model.FindByObjectId(query, key, cb)
model.UpdateByObjectId(query, doc, key, cb)
model.RemoveByObjectId(query, key, cb)
model.parseOID(value, cb)

Test with tpill

Running CRUD sample

npm install
// mongod --dbpath $HOME/data/mpill &
node example/crud.js

Results:

✓ CreateCollection
✓ DropCollection
✓ Insert
✓ Update
✓ FindOne
✓ FindByObjectId
✓ UpdateByObjectId
✓ RemoveByObjectId
✓ Count
✓ DropDB

Statistics: {"pass":10,"fail":0,"warn":0}

RESTful API sample

Clone deck tool to see a restify implementation.

Test with mocha

Keeps definded functions.

mocha
18 passing (20ms)

Code quality with gulp-jshint

npm install gulp
npm install gulp-jshint
gulp

About concern

Full api doc: http://docs.mongodb.org/manual/reference/write-concern/

//Sample with concern
var concern = {w:1}; //Use primary node server

Changelog:

v0.5.1

  • Add Aggregation framework queries.
  • Add tests for mongo v3

v0.5.0

  • Stable version for common queries
0.5.1

9 years ago

0.5.0

9 years ago

0.4.1

9 years ago

0.4.0

9 years ago

0.3.0

9 years ago

0.2.2

9 years ago

0.2.1

9 years ago

0.2.0

9 years ago

0.1.2

9 years ago

0.1.1

9 years ago

0.1.0

10 years ago

0.0.8

10 years ago

0.0.7

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago