2014-12-10 73 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