2014-12-10 56 views
0

我想与OrientDB一起使用SailsJS(使用Oriento作为NodeJS)。建立和定义数据库连接以便在每个模型中都可用的地方是什么地方?SailsJS:在哪里定义数据库连接到不支持的数据库类型(orientdb)?定制中间件?

我将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 
     }); 
    } 
} 

回答

3

帆的作品与DB适配器,帆 - 蒙戈或帆,PostgreSQL的...

你有一个适配器orientDB这里:

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

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

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

+0

我已经看到了,但我认为这是在早期阶段。仔细观察它也依赖于Oriento。所以我只是分叉它,并将在为适配器做出贡献的方式上添加必要的改进。 – 2014-12-11 17:44:05