有没有办法禁用水线并在sails.js 中使用不同的ORM? [英] Is there a way to disable waterline and use a different ORM in sails.js?

查看:20
本文介绍了有没有办法禁用水线并在sails.js 中使用不同的ORM?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的 sails.js 应用程序中用猫鼬替换水线.我正在寻找正确的方法来做到这一点,但我在文档中没有看到如何做到这一点.谁能解释一下如何做到这一点?

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?

推荐答案

通过 .sailsrc 定义覆盖

您可以通过配置覆盖来做到这一点,在您的项目根目录中通过 .sailsrc 定义.基本上你必须阻止整个 Waterline 初始化,当前标记为 orm 钩子.在 .sailsrc 中:

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:

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

您还必须禁用 pubsub 钩子 - 这取决于 orm 钩子.源代码中的相关行:v0.10, v0.9.8

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.

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

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

关于在未来版本的 Sails 中的稳定性,您应该意识到当前钩子系统被标记为不稳定并且禁用钩子是建议反对:

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:

// 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:

注意:由于所讨论的 PR 已合并用于前沿的 git checkouts,因此默认情况下这会被烘焙到 Sails 中.

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

对于 Sails 0.10.x

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

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

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

对于 Sails 0.9.x

用这个替换 app.js:

Replace app.js with this:

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

这篇关于有没有办法禁用水线并在sails.js 中使用不同的ORM?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆