Skip to content

mickelindahl/hapi_handlers_waterline

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status Coverage Status

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 keys
    • log 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 update
    • ext function handler extensions
      • onPreHandler evoked before handler function(request, done) where request is a hapijs request object and done is promise resolve should be called one completion.
      • onPreReply evoked before reply function(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 extensions
      • onPreHandler evoked before handler function(request, done) where request is a hapijs request object and done is promise resolve should be called one completion.
      • onPreReply evoked before reply function(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 function function(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 extensions
      • onPreHandler evoked before handler function(request, done) where request is a hapijs request object and done is promise resolve should be called one completion.
      • onPreReply evoked before reply function(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 function function(request, done) that calls done waterline criteria used to delete models in the database
    • model (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.

Release History

About

A hapijs plugin handlers for database interaction

Resources

Stars

Watchers

Forks

Packages

No packages published