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