比较 Waterline/Sails.js 查询中的两个字段 [英] Compare two fields in Waterline/Sails.js query

查看:42
本文介绍了比较 Waterline/Sails.js 查询中的两个字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Sails.js 应用程序中比较我的 Waterline 查询中的两个字段,例如:SELECT * FROM entity E WHERE E.current <E.max.

I want to compare two fields in my Waterline query in Sails.js application, e.g.: SELECT * FROM entity E WHERE E.current < E.max.

我已经尝试了以下代码,但它希望将整数值而不是列名传递给它:

I've tried the following code, but it's expecting integer value to be passed to it instead of column name:

Entity.find({
  where: {
    current: {'<': 'max'}
  }
});

那么,我如何比较两列?

So, how do I compare two columns?

推荐答案

我进行了一些测试,同时阅读了 Waterline 文档.没有任何迹象表明可以通过 .find().where() 方法对两个字段/列进行比较.参考:http://sailsjs.org/documentation/concepts/models-and-orm/查询语言

I have ran some tests and at the same time read the Waterline documentation. There is no indication of anything that could possibly do comparison of two fields/columns via .find() or .where() methods. Reference: http://sailsjs.org/documentation/concepts/models-and-orm/query-language

相反,我使用 .query() 方法通过 SQL 字符串比较两个字段,例如:

Instead, I have used .query() method to compare two fields via SQL string such as :

Entity.query("SELECT * FROM `Entity` E WHERE E.current < E.max", function( err, res) {
  if(err) {
    //exception
  } else {
    console.log('response',res);
  }
});

这篇关于比较 Waterline/Sails.js 查询中的两个字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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