https://github.com/fritzy/verymodel-hapi
https://github.com/fritzy/verymodel-hapi
Last synced: 7 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/fritzy/verymodel-hapi
- Owner: fritzy
- License: mit
- Created: 2013-12-10T17:50:23.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2013-12-19T19:54:31.000Z (almost 12 years ago)
- Last Synced: 2025-01-25T21:55:27.146Z (8 months ago)
- Language: JavaScript
- Size: 133 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
verymodel-hapi
==============Tools for VeryModel use in Hapi
#Extending Model to be very hapi.
//./models/person.js
var verymodel = require('verymodel');
var veryhapi = require('verymodel-hapi');
var Person = new verymodel.VeryModel({
name: {required: true},
id: {},
});//add hapi functionality to the model factory and instances
veryhapi.makeModelHapi(Person);//extend every instance
Person.extendModel({
save: function () {
//some db save
var request = this.getRequest();
},
refresh: function () {
//kind of like load, but on an already instanciated method
someDBCall(this.id)
}
});//extend model factory
Person.load = function (id) {
var obj = someDBQuery(id);
return Person.create(obj);
};Person.loadByName = function (name) {
// ...
};module.exports = Person;
Meanwhile, at the ranch...
function hapiRoute(request) {
var nlf = Person.hapiCreate(request);
//...
//uses request.payload to create
//nlf.getRequest() returns request
}# Importing Hapi Validators
See test.js for now