1.2.0 • Published 8 years ago
pi-model v1.2.0
PiModel
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.).
Install
npm install pi-model
Usage
// New model definition
var ModelBuilder = require('pi-model'),
User = new ModelBuilder({
'name' : 'UserModel'
});
// Model usage
var myUser = new User({
'firstName' : 'John',
'lastName' : 'Doe'
});
Builder options
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
Validator
You can use pi-validator-tv4 if needed. It is a simple encapsulation of tv4 (validation with JSON schema).
Create a custom validator
If you need to create your own validator, you can base extend pi-validator.
It is an abstraction of the validator.