go-rel / go-rel/rel

Support for JSON field selectors (data->"$.a.b.c")

Open
#375 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
786
Forks
61
Avg merge
4d 11h
Merged PRs (30d)
2

Description

MySQL allows querying a property from a JSON field using [special syntax](https://dev.mysql.com/doc/refman/8.4/en/json.html), for example, like so `SELECT col->"$.mascot" FROM qtest`. In our system, we use normal columns to narrow down results to just a few hundreds rows, but then apply a few JSON filters to further filter and sort records based on the values in the JSON fields. The value stored in JSON is dynamic, and it's not feasible to extract it into a column.

The query looks something like this:

```
SELECT * FROM records WHERE scope = ? AND data->'$.r_12345' != 0 ORDER BY data->'$.r_12345' ASC
```

I can add a filter by JSON field using `rel.FilterFragment` API, but unfortunately, there is nothing similar for `ORDER BY` portion.

What would be the best way to implement it, and is there a workaround? For example, adding support for `col->"..."` to a field escape function or maybe just adding support for `rel.OrderFragment`?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.