scriptbytes
scriptbytes
DTDrizzle Team
Created by scriptbytes on 1/26/2024 in #help
Partial Select - Child array
I have a one-many relationship of recipe->comments. How do I get it to return the comments as an array? const test = await db .select({ ...getTableColumns(recipe), comments: getTableColumns(comment), // This should be an array }) .from(recipe) .leftJoin(comment, eq(recipe.id, comment.recipeId));
5 replies
DTDrizzle Team
Created by scriptbytes on 1/25/2024 in #help
getTableColumns for sub-query
I am very new to drizzle so I'm not sure the best way to do this. I want to create a query, and then query from it and add some calculated fields. This is a rough example: const first = db .select({ ...getTableColumns(recipe), likeCount: sql<number>(select count.....as('likeCount'), commentCount: sql<number>(select count.....as('commentCount'), }) .from(recipe) .as('first'); const test = await db.select({ ...first, columnA: 'something...', columnB: 'something else...' }).from(first).limit(10); The problem is I don't know how to add more columns in my second select (const test = await db.select...). There are columns from my first query I want to do some calculations on. I am using Postgres.
4 replies