- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我对 Bookshelf 有疑问,我想对 json 类型的列使用查询我的表有列 'data' 类型的 json,我想在此列 'team' = 'PSG' 中获取所有元素
我测试:
collection.query('whereRaw', "data->'team'->>'PSG'");
我有这个错误
"argument of WHERE must be type boolean, not type text"
或者我测试
collection.query('where', "data", "#>", "'{team, PSG}'");
我有这个错误
"The operator \"#>\" is not permitted"
最佳答案
简答:
collection.query('where', 'data', '@>', '{"team": "PSG"}');
解释:
假设你有一个表 foos
,其中一个元素 foo
是
------------------------
| id | attr |
------------------------
| 0 |{ "bar": "fooBar"} |
------------------------
| 1 |{ "bar": "fooFoo"} |
------------------------
原始查询就像这样。
select * from "foos" where "attr" @> '{"bar":"fooBar"}';
现在在 Bookshelf 中,如果您有一个代表表 foo 的模型 Foo,那么查询应该是这样的。
Foo.where('attr', '@>', '{"bar":"fooBar"}').fetch().then(function(rows){});
现在你的情况应该是这样的
collection.query('where', 'data', '@>', '{"team": "PSG"}');
希望 Zlatan 批准它。
关于json - Bookshelf.js 哪里有 json 列 Postgresql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27780117/
我想实现这一目标 SELECT id, ( 3959 * acos( cos( radians(37) ) * cos( radians( lat ) ) * cos( radians( lng )
我要表演WHERE - IN查询/操作但正常的地方给出错误。 我要这个 select * from `calendar_event_rsvp` where `event_id` in ('1', '2
我正在尝试使用 knex 进行简单的计数(因为它似乎是 to not be supported by bookshelf yet )。以下代码正在运行: bookshelf.knex('hosts')
我想创建一个脚本作为 cron 任务在我的服务器后台运行。 我希望脚本能够访问 sails 环境(即加载所有模块,尤其是 bookshelf 和 knex,以及数据库连接)。 这样我就可以创建一个看起
我正在尝试播种,保存在用户中,然后获取 userId 并插入到帐户表中: exports.seed = function(knex, Promise) { return Promise.join(
我正在使用 knex 和书架,我的表由作者、标题、内容、计数组成,每个数据如下所示: author: 'John Doe', title: 'aaaaa', content: 'aaaaaaaa' c
我有2个型号 Book: id, name, data (json) Author: id, name 我想用Book方法扩展author模型,该方法在查询withRelated时返回作者。如果我在a
如何使用事务处理 t,我想确保在保存记录之前成功删除该行: var Roles = bookshelf.Collection.extend({ model: Role ); Role.whe
我一直在做许多操作,我希望有一种方法可以“扩展”knex 来完成它们。 我想要类似的东西: oneExists result = knex.count(id).from('table').wh
我正在与 Bookshelf.js 作斗争,希望有人能帮我一把。 我的客户拥有各种类型的联系人(电子邮件地址、Facebook、Skype 等)。所以我分成三个表来标准化类型。我似乎无法找到如何正确查
我正在尝试使用 Express/Bookshelf/Awesomeplete 创建自动完成搜索。 我一直在试图找出如何使用像这样的Where Like 查询将搜索词传递到Bookshelf,我正在从P
我想监控对我的 API 数据库的查询所花费的时间。我使用 Bookshelf 插件 bookshelf-signals 创建了以下函数。 : bookshelf.on('fetching', () =
以下 Bookshelf 模型在保存模型时对用户密码进行哈希处理,唯一的问题是如果我将 model.set() 调用更改为 model.save() 它进入无限保存/更改循环。 var User =
我需要遍历 Bookshelf 集合中的所有模型,计算一些信息,然后将该信息存储回每个模型。为了回滚错误,我在单个事务中执行此操作很重要。 我遇到的问题是我真正能想到的唯一方法是使用 Promise.
我正在使用 karma-jasmine、webpact 运行单元测试。我尝试使用 bookshelf 在 mysql 数据库中插入一条记录。我收到以下错误消息: ReferenceError:书架未定
我正在开发一个已docker化的express.js应用程序。这是我提供给书架的配置信息。 { "database_dev" : { "client": "mysql",
我正在努力弄清楚如何与 Bookshelf.js 和 postgres 建立深厚的关系。 假设我有三个模型,User、Org 和 UserRole ... User 和 Org 具有多对多关系。 Us
Bookshelf.js 中 Collections 的 attach 和 updatePivot 方法似乎都作用于多对多关系,但它们似乎都没有保存或更新( upsert) 多对多关系项。运行 att
我正在尝试使用 bookshelf.js 作为 Postgresql 的 ORM 在 node.js 应用程序中实现基于 Angular 色的访问控制。我有以下架构: USERS ROLES RI
在一个原始的 MySQL 查询中,我有这样的东西: Select total_sales - over_head_costs As net_sales from departments; 如何使用 B
我是一名优秀的程序员,十分优秀!