postgres helper wrapping to_json referencing CTE?
is there a way to create a type safe postgres helper (
recordToJson
) that is similar to jsonObjectFrom, but that references an existing CTE. in essence i want to be able to do something like this
to generate sql like this
so this generates the correct SQL, but lacking any type safety
GitHub
kysely/src/helpers/postgres.ts at 660dfb43d5c48dd74d35f5fedae28f395...
A type-safe typescript SQL query builder. Contribute to kysely-org/kysely development by creating an account on GitHub.
3 Replies
Solution
It's as simple as this https://kyse.link/t2h2a
You don't need that nested select there
I forgot we have a built-in function for
to_json
https://kyse.link/WlgyZamazing! thank you so much. so much simpler ☺️
(tried to mark ✅ but getting
The application did not respond
)