SailsJS: Where to define db connection to not supported db type (orientdb)? Custom Middleware?

155 views Asked by At

I want to use SailsJS with OrientDB (using Oriento for NodeJS). What would be the right place to establish and define the database connection so that it is available in every model?

I put the values for the connection in config/connections.js and the connection itself in /config/http.js as custom middleware. It works but I am absolutely not sure if that is correct

module.exports.http = {

  middleware: {
      custom: true
    },
   customMiddleware: function(app){

      var Oriento = require('oriento');
      var Oserver = Oriento({
        host: sails.config.connections.orientDBServer.host,
        port: sails.config.connections.orientDBServer.port,
        username: sails.config.connections.orientDBServer.username,
        password: sails.config.connections.orientDBServer.password
      });

      db = Oserver.use({
        name: sails.config.connections.orientDBServer.dbname,
        username: sails.config.connections.orientDBServer.username,
        password: sails.config.connections.orientDBServer.password
      });
   }
}
1

There are 1 answers

1
josebaseba On

Sails works with db adapters as sails-mongo or sails-postgresql...

You have an adapter to orientDB here:

https://github.com/vjsrinath/sails-orientdb

I think that that's the best solution, you will have the same methods and attrs that Waterline has.

Btw, don't do the configuration as a custom middleware because every request pass for that functions...