all files / couch/util/ register-database-services.js

18.18% Statements 2/11
100% Branches 0/0
0% Functions 0/2
18.18% Lines 2/11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30                                                        
export function registerDatabaseService(app, couches, serviceName, { url, name }) {
  let couch = couches.couch({ url });
  let db = couch.database(name);
 
  let fullServiceName = `service:${serviceName}`;
 
  app.register(fullServiceName, db, { instantiate: false });
 
  [ 'controller', 'component', 'route' ].forEach(key => {
    app.inject(key, serviceName, fullServiceName);
  });
}
 
/*
registerDatabaseServices(app, {
  db: {
    url: 'http://127.0.0.1:5984',
    name: 'thing'
  },
  ...
});
*/
export function registerDatabaseServices(app, hash) {
  let couches = app.lookup('couch:couches');
  for(let key in hash) {
    registerDatabaseService(app, couches, key, hash[key]);
  }
}