在风帆和水线中混合使用 AND 和 OR 子句 [英] Using mix of AND and OR clause in sails and waterline

查看:27
本文介绍了在风帆和水线中混合使用 AND 和 OR 子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 Sailsjs 及其 ORM Waterline 中使用 OR 和 AND 子句?例如我有一张书本

How can I use OR and AND clause in Sailsjs and its ORM Waterline? For example I have a table of books

 _______________________________________
| book_name | author   | free  | public |  
 _______________________________________
| Book-A    | Author-1 | false | true   |
 ---------------------------------------
| Book-B    | Author-1 | true  | true   |
 ---------------------------------------
| Book-C    | Author-1 | false | false  |
 ---------------------------------------
| Book-D    | Author-2 | true  | true   |
 ---------------------------------------

我想获得 Author-1 的书籍,它们要么是公开的,要么是免费的,即 Book-A 和 Book-B.如何使用 Sails.js 编写此查询

I want to get Books by Author-1 which are either public or free, which is Book-A and Book-B. How do I write this query with Sails.js

推荐答案

为此我们可以使用Waterline的where api,下面是一个例子

For doing so we can use the where api of Waterline, following is an example

Book.find().where(  { or : [ { free  : true }, {   public: true  } ] })
            .where( { author : "Author-1" }  )
            .exec( function (err, books) {
            //Books will be an array containing all the books that matches this criteria
            //Some code here
    }

这篇关于在风帆和水线中混合使用 AND 和 OR 子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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