JD
JD
DTDrizzle Team
Created by miigaarino on 7/4/2023 in #help
Many to many - Planetscale
for anyone curious, I was able to achieve closer to what I wanted using the magic sql function and GROUP_CONCAT:
export const queryAllGroups4 = await db
.select({
groupId: groups.id,
groupName: groups.name,
attendeeTypes: sql<string>`GROUP_CONCAT(${attendeeTypes.name})`,
})
.from(groups)
.leftJoin(groupsToAttendeeTypes, eq(groups.id, groupsToAttendeeTypes.groupId))
.leftJoin(
attendeeTypes,
eq(attendeeTypes.id, groupsToAttendeeTypes.attendeeTypeId)
)
.groupBy(groups.id);
export const queryAllGroups4 = await db
.select({
groupId: groups.id,
groupName: groups.name,
attendeeTypes: sql<string>`GROUP_CONCAT(${attendeeTypes.name})`,
})
.from(groups)
.leftJoin(groupsToAttendeeTypes, eq(groups.id, groupsToAttendeeTypes.groupId))
.leftJoin(
attendeeTypes,
eq(attendeeTypes.id, groupsToAttendeeTypes.attendeeTypeId)
)
.groupBy(groups.id);
42 replies
DTDrizzle Team
Created by miigaarino on 7/4/2023 in #help
Many to many - Planetscale
sorry, must have misread. I think I just assumed this was a frequent enough use case, it would already be a "solved problem" without needing to manually restructure all the data.
42 replies
DTDrizzle Team
Created by miigaarino on 7/4/2023 in #help
Many to many - Planetscale
thanks
42 replies
DTDrizzle Team
Created by miigaarino on 7/4/2023 in #help
Many to many - Planetscale
ahhh. So my attempt to learn how to do it this way is more trouble than worth then? 😅 I was starting to lean this way
42 replies
DTDrizzle Team
Created by miigaarino on 7/4/2023 in #help
Many to many - Planetscale
RQB? Sorry I don't think I know what that means
42 replies
DTDrizzle Team
Created by miigaarino on 7/4/2023 in #help
Many to many - Planetscale
On this topic, I have my two tables created, along with a junction table with the ids. I have successfully used the db.query() syntax so know the tables work, but can't figure out how to get data using the db.select() syntax, and can't seem to find any examples that include how to actually use the response.
I got this far using drizzle docs:
export const selectAllActiveGroups = await db
.select()
.from(groupsToAttendeeTypes)
.leftJoin(groups, eq(groupsToAttendeeTypes.groupId, groups.id))
.leftJoin(
attendeeTypes,
eq(groupsToAttendeeTypes.attendeeTypeId, attendeeTypes.id)
)
.where(
and(
isNull(groups.deletedAt),
eq(groups.active, true),
eq(attendeeTypes.active, true)
)
);
export const selectAllActiveGroups = await db
.select()
.from(groupsToAttendeeTypes)
.leftJoin(groups, eq(groupsToAttendeeTypes.groupId, groups.id))
.leftJoin(
attendeeTypes,
eq(groupsToAttendeeTypes.attendeeTypeId, attendeeTypes.id)
)
.where(
and(
isNull(groups.deletedAt),
eq(groups.active, true),
eq(attendeeTypes.active, true)
)
);
But because its coming from the junction table, the data is no longer in a useful format, and I am a bit lost. I was hoping to stick to the SQL style as much as possible so I better learn it, so any guidance would be appreciated here!
42 replies
TTCTheo's Typesafe Cult
Created by JD on 12/11/2022 in #questions
How to filter the SpaceX API (mongoDB find() based) by a nested array?! Tech Test
The advice on stack overflow was "just change the API scheme" 😂
10 replies
TTCTheo's Typesafe Cult
Created by JD on 12/11/2022 in #questions
How to filter the SpaceX API (mongoDB find() based) by a nested array?! Tech Test
Thanks for trying. At least I can be satisfied it's not just me being stupid. I think it's due to the field being populated in the options. It can only be filtered on the payload id string 😭
10 replies
TTCTheo's Typesafe Cult
Created by JD on 12/11/2022 in #questions
How to filter the SpaceX API (mongoDB find() based) by a nested array?! Tech Test
nope. 200 status, but docs array is empty
10 replies
TTCTheo's Typesafe Cult
Created by JD on 12/11/2022 in #questions
How to filter the SpaceX API (mongoDB find() based) by a nested array?! Tech Test
To clarify, I'm trying to avoid filtering locally so I can use the APIs built in pagination. Worst case I assume the best option is to query the payloads end-point instead to get a list of all launch ids and then query the Launch API with those. 🤷‍♂️
10 replies