Separating results of join into objects of each type
Hey guys, I'm curious if anyone knows a way to unmerge the results of a join into objects of both types. For example, if you have a table User and table Bio, and query a single row which joins those two, the result is an a flat object with keys from both tables. What I'd like to do is separate the result into a User object and Bio object.
Solutions that work but I don't love:
1. manually extracting values from the object based on the current schema. (future changes to schema will break this, so I'd like to avoid that)
2. Multiple database queries for each object (this lengthens load times, which isn't a great solution for me either).
Let me know what you guys think and if you were able to find a good solution for this, or if I should just bite the bullet and go with solution 1.
Solution
koskimas•48d ago
Shawn Long•48d ago
Thanks @koskimas, to summarize the solution referenced from the docs, the idea is to coalesce the results as json so that you can extract different kinds of data from a single query. Makes code a little messier, but solves the problem nicely.
1.4KMembers
View on DiscordWant results from more Discord servers?
More PostsSnippet compilationHi, is it somehow possible to get only part of the compiled code to use it as snippet in ORM? Or vicCreating an 'enum' type columnHi all,
Trying to re-create this MySQL in Kysely
```
...
CREATE TABLE ...(
...
members ENUM('femalError when destructuring QueryCreator in withRecursiveI'm new to Kysely and attempting to migrate a Next app from prisma to kysely. I've generated types, Is `sql.join` the best way to concatenate sql templates?I have some business logic that incrementally builds up a sql WHERE query as a string. It looks likeMultiple calls to values in insert statement?I just had a production bug where I was calling `.values` multiple times on a query object. I've fix0.27.3 is out. Didn't have time to write0.27.3 is out. Didn't have time to write release notes yet since it was a hotfix to support typescriusing pgvector with KyselyFollowing the example here: https://github.com/pgvector/pgvector-node?darkschemeovr=1#kysely
But I Static/reusable custom window functionsHello, I'm trying to buld a properly typed `array_agg` window function and would like to reuse the eIs the Kysely main site down?I just want to confirm if Kysely's main site is downOn Conflict do update set ALL to be inserted columnsHere I am once again with a question for the on conflict bit in postgres. Would there be a way to au