hapi-handlers-waterline
v1.0.1
Published
A collection of usefull route handlers to interact with tables in databases for hapijs server
Downloads
2
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'}),
}
])
});
options
Object or list of objects with the following keyslog
Function 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
options
an object with the following keys.model
(string) table to updateext
function handler extensionsonPreHandler
evoked before handlerfunction(request, done)
where request is a hapijs request object and done is promise resolve should be called one completion.onPreReply
evoked 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.done
should be called with preferred reply payload.done
should 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
options
an object with the following keys.ext
function handler extensionsonPreHandler
evoked before handlerfunction(request, done)
where request is a hapijs request object and done is promise resolve should be called one completion.onPreReply
evoked 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.done
should be called with preferred reply payload. -getCriteria
functionfunction(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
options
an object with the following keys.ext
function handler extensionsonPreHandler
evoked before handlerfunction(request, done)
where request is a hapijs request object and done is promise resolve should be called one completion.onPreReply
evoked 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.done
should 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
options
an object with the following keys. -getCriteria
functionfunction(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.