brynthrax
brynthrax
DTDrizzle Team
Created by brynthrax on 3/17/2024 in #help
Application-defined functions/UDF in LibSQL
unfortunately, not yet.
3 replies
DTDrizzle Team
Created by brynthrax on 8/11/2023 in #help
How to flatten select results from query with left joins (one-to-many)?
so I guess with that said, there's really no library-specific workaround for now except for findMany 😕
18 replies
DTDrizzle Team
Created by brynthrax on 8/11/2023 in #help
How to flatten select results from query with left joins (one-to-many)?
and for the part wherein the json is returned as a string rather than an actual native json object, I gave up trying to solve it. I was browsing through the source code and here are my findings. the relational query (findMany) I mentioned before uses the same json_agg function (and others) you mentioned earlier. and when I looked through the source code, it seems like that they call the native JSON.parse method on that JSON string result. maybe that's why findMany is able to return them as JSON objects rather than strings. for reference in source code, try searching for mapRelationalRow and sqlite-core/query-builders/query.ts
18 replies
DTDrizzle Team
Created by brynthrax on 8/11/2023 in #help
How to flatten select results from query with left joins (one-to-many)?
One thing I know is that if you're using the select method, you can achieve the parent-child format by manually doing this thing:
.select({
articleId: articles.id,
articleName: articles.name,
articleDate: articles.date,
// some other article fields here // manually destructured
images: sql<string>`json_agg("Images".*) AS images`,
})
.select({
articleId: articles.id,
articleName: articles.name,
articleDate: articles.date,
// some other article fields here // manually destructured
images: sql<string>`json_agg("Images".*) AS images`,
})
but if you would like to do it in a less hassle way without those manual destructuring, you can do a relational query via the findMany method. however, I'm trying to stay away from this as there are no native joins yet, they use subqueries under the hood.
18 replies
DTDrizzle Team
Created by brynthrax on 8/11/2023 in #help
How to flatten select results from query with left joins (one-to-many)?
hmmm so you ended up writing raw SQL anyway. I hope there could be an actual workaround for this in the next releases 😀
18 replies
DTDrizzle Team
Created by brynthrax on 8/11/2023 in #help
How to flatten select results from query with left joins (one-to-many)?
thanks a lot for sharing. were you now able to parse the JSON string as an actual JSON object?
18 replies