import { kysely } from "https://deno.land/x/kysely_postgrs_js_dialect@v0.27.4/mod.ts";
const { JSONPathBuilder } = kysely;
Access a property of a JSON object.
If a field is optional, the resulting type will be nullable.
See also at to access elements of JSON arrays.
Examples
db.selectFrom('person').select(eb =>
eb.ref('address', '->').key('city').as('city')
)
The generated SQL (PostgreSQL):
select "address"->'city' as "city" from "person"
Going deeper:
db.selectFrom('person').select(eb =>
eb.ref('profile', '->$').key('website').key('url').as('website_url')
)
The generated SQL (MySQL):
select `profile`->'$.website.url' as `website_url` from `person`
Combined with at:
db.selectFrom('person').select(eb =>
eb.ref('profile', '->').key('addresses').at(0).key('city').as('city')
)
The generated SQL (PostgreSQL):
select "profile"->'addresses'->0->'city' as "city" from "person"
Parameters
key: K