简体   繁体   English

SailsJS:在哪里定义与不支持的数据库类型(orientdb)的数据库连接? 定制中间件?

[英]SailsJS: Where to define db connection to not supported db type (orientdb)? Custom Middleware?

I want to use SailsJS with OrientDB (using Oriento for NodeJS). 我想将SailsJS与OrientDB一起使用(使用Oriento for NodeJS)。 What would be the right place to establish and define the database connection so that it is available in every model? 建立和定义数据库连接以便在每个模型中都可用的正确位置是什么?

I put the values for the connection in config/connections.js and the connection itself in /config/http.js as custom middleware. 我将连接的值放在config / connections.js中,将连接本身放在/config/http.js中作为自定义中间件。 It works but I am absolutely not sure if that is correct 它有效,但是我绝对不确定这是否正确

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

Sails works with db adapters as sails-mongo or sails-postgresql... Sails与db适配器配合使用,如sails-mongo或sails-postgresql ...

You have an adapter to orientDB here: 您在这里有一个orientDB适配器:

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

I think that that's the best solution, you will have the same methods and attrs that Waterline has. 我认为那是最好的解决方案,您将拥有与Waterline相同的方法和属性。

Btw, don't do the configuration as a custom middleware because every request pass for that functions... 顺便说一句,不要将其配置为自定义中间件,因为针对该功能的每个请求都会通过...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM