A postgres helper for aggregating a subquery (or other expression) into a JSONB array.
Examples
While kysely is not an ORM and it doesn't have the concept of relations, we do provide
helpers for fetching nested objects and arrays in a single query. In this example we
use the jsonArrayFrom helper to fetch person's pets along with the person's id.
Please keep in mind that the helpers under the kysely/helpers folder, including
jsonArrayFrom, are not guaranteed to work with third party dialects. In order for
them to work, the dialect must automatically parse the json data type into
JavaScript JSON values like objects and arrays. Some dialects might simply return
the data as a JSON string. In these cases you can use the built in ParseJSONResultsPlugin
to parse the results.
A postgres helper for aggregating a subquery (or other expression) into a JSONB array.
Examples
While kysely is not an ORM and it doesn't have the concept of relations, we do provide helpers for fetching nested objects and arrays in a single query. In this example we use the
jsonArrayFromhelper to fetch person's pets along with the person's id.Please keep in mind that the helpers under the
kysely/helpersfolder, includingjsonArrayFrom, are not guaranteed to work with third party dialects. In order for them to work, the dialect must automatically parse thejsondata type into JavaScript JSON values like objects and arrays. Some dialects might simply return the data as a JSON string. In these cases you can use the built inParseJSONResultsPluginto parse the results.The generated SQL (PostgreSQL):