Skip to content
This repository has been archived by the owner on Apr 18, 2020. It is now read-only.

Latest commit

 

History

History
46 lines (40 loc) · 1.42 KB

README.md

File metadata and controls

46 lines (40 loc) · 1.42 KB

hapi-massive

Hapi plugin for massive.js 2.0

Install

var plugin = {
  register: require("hapi-massive"),
  options: {
    connectionString: "postgres://username:password@localhost/database"
  }
};

server.register(plugin, function(error){
  if(error){
    console.error("failed to load plugin: ", err);
  }
}

hapi-massive comes free with promises! Promises wrap all your sql files as well as the relational bits

Examples

Clean code! (Say that you have a table named user and a sql file named createUser.sql that returns a user object upon creation)

var db = request.plugins["hapi-massive"].db;
var userdeets = [...userinfo];
db.createUserAsync().then(function(user){
  console.log("woot! user created. ", user); 
});

Or go crazy with generators! (using co.js)

var db = request.plugins["hapi-massive"].db;
co(function*(){
  var userdeets = [...userinfo];
  var user = yield db.createUserAsync(userdeets); // wow does this look like its in sync or what?
  console.log(user);
}).catch(function(err){
  console.log("there can't be errors in an example!");
});

Special thanks

Heavily inspired by hapi-node-postgres.

Promises brought to you by bluebird