loopbackio / loopbackio/loopback-connector-postgresql

MongoDB extended operator rules erroneously applied to SQL databases and json bodies

未关闭
#534 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

bug
主要语言
JavaScript
星标
118
派生
184
平均合并
1 天 22 小时
30 天内合并 PR
5

描述

NOTE: This is a bug in loopback-datasource-juggler, however the issue template there explicitly requests filing bugs in this project so 🤷

https://github.com/loopbackio/loopback-datasource-juggler/pull/1662 brought in some validation code that only is applicable to MongoDB, and is making certain operation on JSON properties/columns with SQL databases excessively difficult.

It is already impossible to do json equality searches out of the box due to #477, however that issue has a fairly straight forward workaround.

That workaround fails if the JSON object you are searching for contains any properties starting with a $ at the top level however, because they are interpreted as extended operators, even if they cannot possibly actually be such.

For example, pretend #477 was already fixed and you wrote this where expression:

{ where: { propertyName: { eq: { $foo: 'bar' } } } }

The $foo, AFAICT, cannot possibly be an operator because you already specified the eq operator.

Furthermore, if you're not using MongoDB, then this whole thing is moot anyways and these checks are inapplicable.

Steps to reproduce

  1. Create an entity type with a property of object type mapped to a SQL field of json type
  2. Insert a record that has a key in this property, at the top level, whose name starts with a $
  3. Attempt to do a find() call to locate this record using an equality match on that property

Current Behavior

  1. #477 gets in your way
  2. Even with the workaround for that, Loopback throws a OPERATOR_NOT_ALLOWED_IN_QUERY error and refuses to run your query

Expected Behavior

Loopback should be able to do property = ? queries on JSON fields against SQL databases.

Link to reproduction sandbox

WIP

Additional information

Same environment as #477

Related Issues

  • #477

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 loopback-datasource-juggler 的 pull request 1662 引入的验证代码开始,并通过对包含顶层 $ 键的 PostgreSQL JSON 字段执行 find() 调用来重现该问题。完成的标准是 SQL JSON 相等查询不再引发 OPERATOR_NOT_ALLOWED_IN_QUERY,同时 MongoDB 扩展操作符验证仍然适用。

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript, postgresql
领域
database
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。