We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hi there,
Is it possible to create a JSON array of column values in Kysely?
const result = await db .selectFrom('person') .select((eb) => [ 'id', jsonArrayFrom( eb.selectFrom('pet') .select('pet.name') .whereRef('pet.owner_id', '=', 'person.id') .orderBy('pet.name') ).as('pets') ]) .where('id', '=', 1) .executeTakeFirst()
{ "id": 1, "pets": [ { "name": "Ace" }, { "name": "Zuko" } ] }
Is it possible to create a flat array like the following using Kysely?
{ "id": 1, "pets": [ "Ace", "Zuko" ] }
select `person`.`id`, ( select cast(coalesce(json_arrayagg( `agg`.`name` ), '[]') as json) from ( select `pet`.`name` from `pet` where `pet`.`owner_id` = `person`.`id` order by `pet`.`name` ) as `agg` ) as `pets` from `person` where `person`.`id` = 1;
I looked for similar issues, but I only found #819, which is loosely related. Sorry if I missed something!
The text was updated successfully, but these errors were encountered:
Maybe you can create a helper similar to the one on the documentation: https://kysely.dev/docs/recipes/relations#the-json-data-type-and-functions
Sorry, something went wrong.
No branches or pull requests
Hi there,
Is it possible to create a JSON array of column values in Kysely?
For example, this Kysely query...
...would result in nested data like this.
Is it possible to create a flat array like the following using Kysely?
This MySQL query would work, but I don't know how to implement it in Kysely.
I looked for similar issues, but I only found #819, which is loosely related. Sorry if I missed something!
The text was updated successfully, but these errors were encountered: