0

我想将 SailsJS 与 OrientDB 一起使用(将 Oriento 用于 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
      });
   }
}
4

1 回答 1

3

Sails 与数据库适配器一起工作,如sails-mongo 或sails-postgresql...

你有一个 orientDB 的适配器:

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

我认为这是最好的解决方案,您将拥有与 Waterline 相同的方法和属性。

顺便说一句,不要将配置作为自定义中间件进行,因为每个请求都会通过该功能...

于 2014-12-11T15:23:33.130 回答