Using `.orderBy` in JSON
Hey,
I have a schema that roughly looks like this
and I want to query the db like that it gives me the top 10 Members with the highest
activity.messages
count. I figured out how I can orderBy but not inside of a json.Solution:Jump to solution
try something like:
```ts
const rows = await kysely
.selectFrom("member")...
25 Replies
Hey 👋
Are you using Kysely 0.26.x? what dialect are you using?
pg (postgres) and I use newest Kysely
In 0.26.x we've introduced type-safe JSON traversal, it's not documented yet in kysely.dev site, only in API docs and in the IDE.
Lemme know if this works for you:
https://kyse.link/?p=s&i=hKiV5qAL1BLLi3tvlwEq
will try when I’m home, than you :)
![think](https://cdn.discordapp.com/emojis/731900142726414352.gif)
![](https://cdn.answeroverflow.com/1134551066906730506/image.png)
![](https://cdn.answeroverflow.com/1134551235551318106/image.png)
nvm was just vs code having it's moment
did it work?
process crashes with
If I comment the
.orderBy
away it works![](https://cdn.answeroverflow.com/1134552983082897498/image.png)
what postgres version?
pg (npm package) or postgres on the server?
server
PostgreSQL 14.8 (Ubuntu 14.8-0ubuntu0.22.04.1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 11.3.0-1ubuntu1~22.04.1) 11.3.0, 64-bit
I've added some test cases for json traversal in order by clauses https://github.com/kysely-org/kysely/pull/621 and everything seems to be OK.
we use pg 8.11.0 and postgres 15.x images.