Jeyprox
Jeyprox
Explore posts from servers
DTDrizzle Team
Created by Jeyprox on 5/25/2023 in #help
RQB | using specific fields from a query against relations
is there any way to implement something like this with RQB rn?
9 replies
DTDrizzle Team
Created by rykuno on 5/28/2023 in #help
Relation Query - Get likes in post
currently there is no way to use the SQL count inside a relational query, see the warning here https://orm.drizzle.team/docs/rqb#include-custom-fields. however, you can still achieve what you need with relational queries like this:
const postData = await db.query.posts.findMany({
where: eq(posts.eventId, params.id),
with: {
likes: {
columns: {
id: true,
userId: true,
}
},
author: true
}
})
const posts = postData.map((post) => ({
likes: post.likes.length,
hasLiked: post.likes.some((like) => like.userId === yourUserId),
post: post,
post: post.author
}));
const postData = await db.query.posts.findMany({
where: eq(posts.eventId, params.id),
with: {
likes: {
columns: {
id: true,
userId: true,
}
},
author: true
}
})
const posts = postData.map((post) => ({
likes: post.likes.length,
hasLiked: post.likes.some((like) => like.userId === yourUserId),
post: post,
post: post.author
}));
there might be some small things that are wrong since it wrote it here in discord, but generally this is how you could do it :)
7 replies
DTDrizzle Team
Created by Jeyprox on 5/25/2023 in #help
RQB | using specific fields from a query against relations
however posts.tags has a type of Many<"tags>" that doesn't seem to allow for what i have in mind
9 replies
DTDrizzle Team
Created by Jeyprox on 5/25/2023 in #help
RQB | using specific fields from a query against relations
i'm looking for something that might look like: where: (posts) => inArray(posts.tags.name, tagList) with:
with: {
tags: {
name: true,
}
}
with: {
tags: {
name: true,
}
}
9 replies
DTDrizzle Team
Created by Jeyprox on 4/23/2023 in #help
missing type declarations in mysql-core imports (>v0.25.1)
just saw that there were some changes to the imports
4 replies
DTDrizzle Team
Created by Jeyprox on 4/23/2023 in #help
missing type declarations in mysql-core imports (>v0.25.1)
ah, ty for specifying :D
4 replies
DTDrizzle Team
Created by Jeyprox on 4/17/2023 in #help
when using planetscale, using the `.$with()` and `.with()` clauses causes error
yep, sorry
5 replies
DTDrizzle Team
Created by Jeyprox on 4/17/2023 in #help
when using planetscale, using the `.$with()` and `.with()` clauses causes error
i couldn't seem to find anything, but i'll try to push my google skills to the limit 🙂
5 replies
DTDrizzle Team
Created by mmurto on 4/12/2023 in #help
How to count joined table?
you should be able to do something along the lines of:
await db.select({
teamName: team.teamname,
time: team.team_timestamp
strength: sql<number>`count(${player.team_id})`
}).from(team)
.leftJoin(player, eq(team.team_id, player.team_id))
.groupBy(team.team_id)
.orderBy(desc(sql`count(${player.team_id})`));
await db.select({
teamName: team.teamname,
time: team.team_timestamp
strength: sql<number>`count(${player.team_id})`
}).from(team)
.leftJoin(player, eq(team.team_id, player.team_id))
.groupBy(team.team_id)
.orderBy(desc(sql`count(${player.team_id})`));
this is not exactly what you're trying to do but should give you an idea of how you can achieve something like this. otherwise you can also just leftJoin the other tables and write a function to aggregate the results yourself
2 replies