SailsJS:在哪里定义db连接到不支持的db类型(orientdb)?自定义中间件?

时间:2014-12-10 23:39:22

标签: javascript node.js sails.js orientdb oriento

我想在OrientDB中使用SailsJS(使用Oriento for NodeJS)。什么是建立和定义数据库连接的正确位置,以便在每个模型中都可用?

我将config / connections.js中的连接值和/config/http.js中的连接本身作为自定义中间件。它有效,但我绝对不确定这是否正确

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 个答案:

答案 0 :(得分:3)

Sails可以将数据库适配器用作sails-mongo或sails-postgresql ...

你有一个适配器到orientDB:

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

我认为这是最好的解决方案,你将采用与Waterline相同的方法和方法。

顺便说一下,不要将配置作为自定义中间件进行,因为每个请求都会传递给该函数...