bookshelf.js-条件条件下的嵌套语句 [英] bookshelf.js - nested statement in where condition

查看:49
本文介绍了bookshelf.js-条件条件下的嵌套语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在bookshelf.js中编写以下查询?

select * from Table where (b=2 or b=3) and c = 4;

我主要关心嵌套部分(b = 2或b = 3).

解决方案

由于书架是基于 knex 构建的,因此我在 knex.js 文档中进行了搜索. /p>

参考链接: https://knexjs.org/#Builder-where

knex('Table').where(function(){
  this.where('b', 2).orWhere('b', 3)
}).andWhere({'c': 4})

How can I write the below query in bookshelf.js?

select * from Table where (b=2 or b=3) and c = 4;

I am mainly concerned about the nested part (b=2 or b=3).

解决方案

Since bookshelf is built on knex, I was searching for this in knex.js documentation.

Reference Link: https://knexjs.org/#Builder-where

knex('Table').where(function(){
  this.where('b', 2).orWhere('b', 3)
}).andWhere({'c': 4})

这篇关于bookshelf.js-条件条件下的嵌套语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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