hapi-handlers-waterline
v1.0.1
Published
A collection of usefull route handlers to interact with tables in databases for hapijs server
Maintainers
Readme
Hapi handlers waterline
A hapi with that makes a couple of useful handlers available to the server for updating tables in databases using hapi-waterline OCR
Installation
npm install --save hapi-handlers-waterline
Usage
'use strict'
const Hapi = require( 'hapi' );
const server = new Hapi.Server( { port: 3000 } );
server.register( {
register: require( 'hapi-waterline-handlers' ),
options: {
log: console.error
}
}).then(()=>{
server.route([
{
method: 'POST',
path:'/test/create',
handler: server.methods.handler.create({model:'test'}),
}
])
});optionsObject or list of objects with the following keyslogFunction to print out error logs
Methods
The handler is attached to hapijs server.methods
handler
handler~create() ⇒
Returns a handler for creating a database entry/entries with data in
request.payload where request is a hapijs request
object
optionsan object with the following keys.model(string) table to updateextfunction handler extensionsonPreHandlerevoked before handlerfunction(request, done)where request is a hapijs request object and done is promise resolve should be called one completion.onPreReplyevoked before replyfunction(request, models, done)where request is a hapijs request object, models is sails create return models object and done is promise resolve should be called one completion.doneshould be called with preferred reply payload.doneshould be called with preferred reply payload.
Kind: inner method of handler
Returns: function(request, reply)
Api: public
handler~update() ⇒
Returns a handler for updating a database with data in
request.payload where request is a hapijs request
object
optionsan object with the following keys.extfunction handler extensionsonPreHandlerevoked before handlerfunction(request, done)where request is a hapijs request object and done is promise resolve should be called one completion.onPreReplyevoked before replyfunction(request, models, done)where request is a hapijs request object, models is sails create return models object and done is promise resolve should be called one completion.doneshould be called with preferred reply payload. -getCriteriafunctionfunction(request, done)that calls done waterline criteria used to update models in the database
model(string) table to update
Kind: inner method of handler
Returns: function(request, reply)
Api: public
handler~get() ⇒
Returns a handler used to retrieve entry/entries from a database
optionsan object with the following keys.extfunction handler extensionsonPreHandlerevoked before handlerfunction(request, done)where request is a hapijs request object and done is promise resolve should be called one completion.onPreReplyevoked before replyfunction(request, models, done)where request is a hapijs request object, models is sails create return models object and done is promise resolve should be called one completion.doneshould be called with preferred reply payload. waterline criteria used to get models from the database
model(string) table to update
Kind: inner method of handler
Returns: function(request, reply)
Api: public
handler~destroy() ⇒
Delete a database entry/entries
optionsan object with the following keys. -getCriteriafunctionfunction(request, done)that calls done waterline criteria used to delete models in the databasemodel(string) table to delete entries in
Kind: inner method of handler
Returns: function(request, reply)
Api: public
Test
npm run-script test
Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.
