A super simple, pluggable model.
$ component install component/model
var model = require('model');
var defaults = require('model-defaults');
var http = require('model-http');
/**
* User model.
*/
var User = model()
.use(http('/users'))
.use(defaults())
.attr('id')
.attr('name')
.attr('email')
.attr('created', { default: function () { return new Date(); }})
.attr('version', { default: 1 });
/**
* In use...
*/
var user = new User({ name: 'Fred' });
user.name('George');
user.email('george@washington.gov');
user.save(function (err) {
if (err) throw err;
console.log('saved', user.toJSON());
});- TODO
Return a new model constructor.
Use the given plugin fn.
Set the model's primary key, which defaults to 'id'.
Define a new model attr by name with optional options. Doing this will create a getter/setter method on the prototype with the same name.
Get the value of the model's primary attribute, or set it to value.
Get the value of an <attr>, or set it to a value.
Set multiple attributes at a time with an obj.
Get the value of attr.
Check if attr is not null or undefined.
Return a JSON representation of the model.
MIT