1.0.1 • Published 8 years ago

hapi-linvodb v1.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
8 years ago

hapi-linvodb Build Status codecov.io npm version

Simple Hapi plugin for linvodb3

Installation

npm install hapi-linvodb

Usage

'use strict';

const Hapi = require('hapi');

// Create a server with a host and port
const server = new Hapi.Server();

server.connection({
    host: 'localhost',
    port: 8000
});

server.register({
    register: require('hapi-linvodb'),
    options: {
      modelName: 'test',
      filename: 'testlinvo.db',
      schema: {}
    }
}, (err) => {

    server.route({
        method: 'GET',
        path: '/',
        handler: (request, reply) => {

            // Access plugin
            var db = server.plugins['hapi-linvodb'].db;

            // Use requests database and create requests database if it does not exist
            db.insert({ a: 1 }, (err, doc) => {

                reply({ message: 'request added to database' });
            });

            // If using a schema you have to create a new object otherwise it's ignored
            const user = new db({});
            user.name = 'Adam';

            user.save(() => {

              reply({ message: 'request added to database' });
          });

        }
    });
});

// Start the server
server.start(() => {

    console.info(`Hapi times at ${server.info.uri}`);
});

License

MIT 2016