PiModel is a simple data model representation that allows data validation and some basic features.
It is aimed to be used in a more organized data accesses (repository, datamapper, datasource, etc.).
npm install pi-model
// New model definition
var ModelBuilder = require('pi-model'),
User = new ModelBuilder({
'name' : 'UserModel'
});
// Model usage
var myUser = new User({
'firstName' : 'John',
'lastName' : 'Doe'
});
The model builder accepts the following options :
{
'name' : String,
'description' : Object,
'validator' : Function
}
name
: String used to define the modeldescription
: Object describing custom information of the modelvalidator
: Instance used to validate data over the schema
You can use pi-validator-tv4 if needed. It is a simple encapsulation of tv4 (validation with JSON schema).
If you need to create your own validator, you can base extend pi-validator.
It is an abstraction of the validator.