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

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

问题描述

我想在我的 sails.js 应用程序中用mongoose替换水线。我正在寻找正确的方法来做到这一点,但我没有看到文档中的内容。谁能解释怎么做?

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 hook。在.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 lift

  • sails console

  • 节点app.js(因为 commit 862c053a66 ),请参阅为旧版本制作app.js使用.sailsrc

  • sails lift
  • sails console
  • node app.js (since commit 862c053a66), see "Making app.js use .sailsrc" for older versions

关于在未来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:

  • https://github.com/balderdashy/sails-docs/issues/69
  • https://github.com/balderdashy/sails/issues/1077

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

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。你可以用这个替换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天全站免登陆