Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QueryBuilder and JSON fields #2839

Closed
pphunor72 opened this issue Mar 1, 2022 · 0 comments
Closed

QueryBuilder and JSON fields #2839

pphunor72 opened this issue Mar 1, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@pphunor72
Copy link

Describe the bug
QueryBuilder does not generate proper SQL statement.

To Reproduce
Steps to reproduce the behavior:

  1. I have an entity with optional lastPos field of type JSONB, and I want to update it, and use it to build a where condition as well.

  2. Try to run the following:

qb.update(details).where(
{ $and: [
    { id: 'b47f1cca-90ca-11ec-99e0-42010a5d800c' },
    { $or: [
	    { lastPos: { $eq: null } },
	    { lastPos: { time: { $lt: 1646147306 } } }
    ]}
]});
  1. The resulting query is as follows:
update "devices" set "last_pos" = '{...}'
where "id" = 'b47f1cca-90ca-11ec-99e0-42010a5d800c'
and ("d0"."last_pos"->>'undefined' is null or ("d0"."last_pos"->>'time')::float8 < 1646147306)
  1. The issues:
    • "d0" table alias is not set, but it is used.
    • cannot check if this JSONB field is null or not. At least the same check as for any other non-JSONB type field does not work. How should be this done properly?

Versions

Dependency Version
node 16.13.1
mikro-orm 5.0.5
your-driver postgresql
@B4nan B4nan added the bug Something isn't working label Mar 12, 2022
@B4nan B4nan closed this as completed in 5c0674e Mar 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants