ngoose

models done like mongoose, but storage agnostics

ngoose

models done like mongoose, but storage agnostics. ngoose does just one think: instantiate new objects based on a schema definition.

Install the module with: npm install ngoose --save

###Then use like this:

var model = require("../lib/ngoose");
 
var user=model({
    age: Number,
    name: String
}),
 
instance=user();
 

instance will contains:

{
    age: 0,
    name: ""
}

###You can supply data to the factory method:

 
var instance=user({
    name: "Garibaldi"
});
 

instance will contains:

{
    age: 0,
    name: "Garibaldi"
}

###Supplied fields that are not defined in schema are not inserted in created instance:

 
var instance=user({
    name: "Garibaldi",
    address: "somewhere"
});
 

instance will contains:

{
    age: 0,
    name: "Garibaldi"
}

###You can specify default values in schema:

 
var user=model({
    address: [String,"somewhere"],
    name: [String,"Garibaldi"]
}),
 
var instance=user();
 

instance will contains:

{
    address: "somewhere",
    name: "Garibaldi"
}

###You can compose models with other models or with inlined objects:

        var user = model({
                name: [String,"unknown"],
                cool: [Boolean,true]
            }),
            bill = model({
                customer: user,
                payment: {
                    terms:String,
                    days:[Number,30]
                }
            }),
            instance = bill();

instance will contains:

{
    customer: {
        name: 'unknown',
        cool: true
    },
    payment: { terms: '', days: 30 }
}

See test folder for usage examples

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality.

Copyright (c) 2013 Andrea Parodi
Licensed under the MIT license.