有没有办法禁用水线并在sails.js中使用不同的ORM?

时间:2021-01-12 02:33:55

I'd like to replace waterline with mongoose in my sails.js application. I'm looking for the correct way to do this, but I don't see how in the documentation. Can anyone explain how to do this?

我想在我的sails.js应用程序中用mongoose替换水线。我正在寻找正确的方法来做到这一点,但我没有看到文档中的内容。任何人都可以解释如何做到这一点?

1 个解决方案

#1


26  

Defining overrides via .sailsrc

You could do this via config overrides, to be defined via .sailsrc in your project root. Basically you have to prevent the entire Waterline initialization, currently tagged as orm hook. In .sailsrc:

您可以通过配置覆盖执行此操作,通过项目根目录中的.sailsrc进行定义。基本上你必须阻止整个Waterline初始化,目前标记为orm hook。在.sailsrc中:

{
  "hooks": {
    "orm": false,
    "pubsub": false
  }
}

You'll have to disable the pubsub hook as well - it depends on the orm hook. Relevant lines in the source: v0.10, v0.9.8.

您还必须禁用pubsub挂钩 - 它取决于orm挂钩。源中的相关行:v0.10,v0.9.8。

This will switch off the orm hook for the following start commands:

这将关闭以下启动命令的orm挂钩:

  • sails lift
  • 帆升降机
  • sails console
  • 帆控制台
  • node app.js (since commit 862c053a66), see "Making app.js use .sailsrc" for older versions
  • node app.js(自提交862c053a66),请参阅旧版本的“使app.js使用.sailsrc”

Concerning the stability of this in future versions of Sails you should be aware of the fact that the hook system currently is tagged as unstable and disabling hooks is advised against:

关于在未来版本的Sails中的稳定性,你应该知道钩子系统当前被标记为不稳定的事实,并建议禁用挂钩:

// Allow disabling of hooks by setting them to "false"
// Mostly useful for testing, and may cause instability in production!

Additional information can be found here:

其他信息可以在这里找到:

Making app.js use .sailsrc

Note: This is baked into Sails by default since the discussed PR was merged for bleeding edge git checkouts.

注意:默认情况下,这会被捆绑到Sails中,因为讨论的PR被合并用于边缘git签出。

For Sails 0.10.x

对于Sails 0.10.x

To make .sailsrc apply to app.js you could replace line 37 in app.js with this:

要使.sailsrc适用于app.js,您可以用以下代码替换app.js中的第37行:

// app.js, following line 36
var fs = require('fs');
var sailsRc = __dirname + '/.sailsrc';
var config = {};

fs.exists(sailsRc, function(exists){
   if (!exists) return sails.lift();

   fs.readFile(sailsRc, 'utf8', function(err, data){
     if (err) {
       console.warn('Error while reading .sailsrc:' + err);
     }

     try {
       config = JSON.parse(data);
     } catch(e) {
       console.warn('Error while parsing .sailsrc:' + err);
     }

     sails.lift(config);
   });
});

For Sails 0.9.x

对于Sails 0.9.x.

Replace app.js with this:

用这个替换app.js:

// Start sails and pass it command line arguments
var fs = require('fs'),
    optimist = require('optimist'),
    sails = require('sails');

var sailsRc = __dirname + '/.sailsrc';
var config = optimist.argv;

fs.exists(sailsRc, function(exists){
  if (!exists) return sails.lift(config);

  fs.readFile(sailsRc, 'utf8', function(err, data){
    if (err) {
      console.warn('Error while reading .sailsrc:' + err);
    }

    try {
      config = sails.util.merge(config, JSON.parse(data));
    } catch(e) {
      console.warn('Error while parsing .sailsrc:' + err);
    }

    sails.lift(config);
 });
});

#1


26  

Defining overrides via .sailsrc

You could do this via config overrides, to be defined via .sailsrc in your project root. Basically you have to prevent the entire Waterline initialization, currently tagged as orm hook. In .sailsrc:

您可以通过配置覆盖执行此操作,通过项目根目录中的.sailsrc进行定义。基本上你必须阻止整个Waterline初始化,目前标记为orm hook。在.sailsrc中:

{
  "hooks": {
    "orm": false,
    "pubsub": false
  }
}

You'll have to disable the pubsub hook as well - it depends on the orm hook. Relevant lines in the source: v0.10, v0.9.8.

您还必须禁用pubsub挂钩 - 它取决于orm挂钩。源中的相关行:v0.10,v0.9.8。

This will switch off the orm hook for the following start commands:

这将关闭以下启动命令的orm挂钩:

  • sails lift
  • 帆升降机
  • sails console
  • 帆控制台
  • node app.js (since commit 862c053a66), see "Making app.js use .sailsrc" for older versions
  • node app.js(自提交862c053a66),请参阅旧版本的“使app.js使用.sailsrc”

Concerning the stability of this in future versions of Sails you should be aware of the fact that the hook system currently is tagged as unstable and disabling hooks is advised against:

关于在未来版本的Sails中的稳定性,你应该知道钩子系统当前被标记为不稳定的事实,并建议禁用挂钩:

// Allow disabling of hooks by setting them to "false"
// Mostly useful for testing, and may cause instability in production!

Additional information can be found here:

其他信息可以在这里找到:

Making app.js use .sailsrc

Note: This is baked into Sails by default since the discussed PR was merged for bleeding edge git checkouts.

注意:默认情况下,这会被捆绑到Sails中,因为讨论的PR被合并用于边缘git签出。

For Sails 0.10.x

对于Sails 0.10.x

To make .sailsrc apply to app.js you could replace line 37 in app.js with this:

要使.sailsrc适用于app.js,您可以用以下代码替换app.js中的第37行:

// app.js, following line 36
var fs = require('fs');
var sailsRc = __dirname + '/.sailsrc';
var config = {};

fs.exists(sailsRc, function(exists){
   if (!exists) return sails.lift();

   fs.readFile(sailsRc, 'utf8', function(err, data){
     if (err) {
       console.warn('Error while reading .sailsrc:' + err);
     }

     try {
       config = JSON.parse(data);
     } catch(e) {
       console.warn('Error while parsing .sailsrc:' + err);
     }

     sails.lift(config);
   });
});

For Sails 0.9.x

对于Sails 0.9.x.

Replace app.js with this:

用这个替换app.js:

// Start sails and pass it command line arguments
var fs = require('fs'),
    optimist = require('optimist'),
    sails = require('sails');

var sailsRc = __dirname + '/.sailsrc';
var config = optimist.argv;

fs.exists(sailsRc, function(exists){
  if (!exists) return sails.lift(config);

  fs.readFile(sailsRc, 'utf8', function(err, data){
    if (err) {
      console.warn('Error while reading .sailsrc:' + err);
    }

    try {
      config = sails.util.merge(config, JSON.parse(data));
    } catch(e) {
      console.warn('Error while parsing .sailsrc:' + err);
    }

    sails.lift(config);
 });
});