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

Support for operators in JSON columns #1487

Closed
evenfrost opened this issue Feb 23, 2021 · 0 comments
Closed

Support for operators in JSON columns #1487

evenfrost opened this issue Feb 23, 2021 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@evenfrost
Copy link
Contributor

evenfrost commented Feb 23, 2021

Describe the bug
Querying a JSON column with condition operators is not currently supported and results in a wrong query.

To Reproduce
Steps to reproduce the behavior:

// 'data' is JSON column and 'created_at' is nested field
await myRepository.count({
  data: {
    created_at: {
      $lte: '2020-02-23T16:00:33.036Z',
    },
  },
});
// myEntity.ts (entity definition)
interface Data {
  created_at: string;
}

@Entity({ tableName: 'mytable' })
export default class MyEntity extends BaseEntity {
  @Property({ type: 'json' })
  data: Data;
}

Generated query is:

select count(distinct("e0"."id")) as "count" from "mytable" as "e0" where "data"->'created_at'->>'$lte' = '2020-02-23T16:00:33.036Z'

$lte is misunderstood as a nested field of created_at field.

Expected behavior

select count(distinct("e0"."id")) as "count" from "mytable" as "e0" where "data"->>'created_at' >= '2020-02-23T16:00:33.036Z'

Versions

Dependency Version
node 14.15.4
typescript 4.1.5
mikro-orm 4.4.4
pg 8.5.1
@B4nan B4nan added the bug Something isn't working label Feb 25, 2021
@B4nan B4nan closed this as completed in cb5e715 Feb 25, 2021
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