mongorito-tcomb
Bring schema validation to Mongorito thanks to tcomb
Install
npm i -S mongorito-tcomb
Usage (ES6)
import co from 'co'
import t from 'tcomb'
import Mongorito, {Model} from 'mongorito-tcomb'
class User extends Model {
get Schema() {
return t.struct({
name: t.String,
surname: t.maybe(t.String)
});
}
}
co(function *(val) {
yield Mongorito.connect('localhost/mongo-tcomb-playground');
var valid = new User({name: "Valid"});
yield valid.save();
var invalid = new User({name: 'Invalid', surname: 88});
try {
yield invalid.save();
} catch (e) {
console.log(e);
}
yield Mongorito.disconnect();
});
For coffeescript, you can see example.coffee
API
patch: (Model) -> PatchedModel
The patch function can be useful to combine different Mongorito plugins. It take a class,
extend it then return the extended class.
TODOS