Get unlimited public & private packages + package-based permissions with npm Pro.Get started »

hapi-documentdb

1.1.4 • Public • Published

hapi-documentdb

Hapi plugin for documentdb

installation

npm install hapi-documentdb --save

usage

server.register(
    [{
        register: require('hapi-documentdb'),
        options: {
            endpoint: process.env.AZURE_DOCUMENTDB_ENDPOINT,
            masterKey: process.env.AZURE_DOCUMENTDB_MASTERKEY
        }
    }],
    function (err) {
 
        if (err) {
            console.error(err);
        }
    }
);
 
var client = server.plugins['hapi-documentdb'].client;
var dbMethod = server.plugins['hapi-documentdb'].methods;
 
var database, collection;
 
dbMethod.getOrCreateDatabase('exampleDb', function (err, db) {
 
    if (err) {
        return server.log(err);
    }
    database = db;
    dbMethod.getOrCreateCollection(database._self, 'tasks', function (err, coll) {
 
        if (err) {
            return server.log(err);
        }
        collection = coll;
    });
});
 
server.route(
{
    method: 'GET',
    path: '/tasks/{id}',
    handler: function (request, reply) {
        client.queryDocuments(
            collection._self,
            "SELECT * FROM docs d WHERE d.id = '" + request.params.id + "'"
        ).toArray(function (err, results) {
            if (err) {
                server.log('error', 'Query ' + err);
                return reply(err);
            }
            reply(null, results);
        });
    }
});

Tests

There are no tests yet as this is just thrown together. Will get to it later.

Install

npm i hapi-documentdb

DownloadsWeekly Downloads

1

Version

1.1.4

License

MIT

Last publish

Collaborators

  • avatar