Web Dev Cody
Web Dev Cody2y ago

doing table joins

is there a best practice way to do joins? I kindof wish I could do this:
return participants
.filter((submission) => !!submission.videoUrl)
.map((submission) => ({
...submission,
votedBy: submission.voteIds.map(
async (votedByUserId) => (await ctx.db.get(votedByUserId))?.name
),
}));
return participants
.filter((submission) => !!submission.videoUrl)
.map((submission) => ({
...submission,
votedBy: submission.voteIds.map(
async (votedByUserId) => (await ctx.db.get(votedByUserId))?.name
),
}));
but that fails when I run it
3 Replies
Web Dev Cody
Web Dev CodyOP2y ago
I guess I just needed this:
return await Promise.all(
participants
.filter((submission) => !!submission.videoUrl)
.map(async (submission) => ({
...submission,
votedBy: await Promise.all(
submission.voteIds.map(
async (votedByUserId) => (await ctx.db.get(votedByUserId))?.name
)
),
}))
return await Promise.all(
participants
.filter((submission) => !!submission.videoUrl)
.map(async (submission) => ({
...submission,
votedBy: await Promise.all(
submission.voteIds.map(
async (votedByUserId) => (await ctx.db.get(votedByUserId))?.name
)
),
}))
I guess I'm wondering if there is room for using typescript to prevent objects with un awaited promises
Michal Srb
Michal Srb2y ago
There's a typescript eslint rule that warns about unawaited promises: https://typescript-eslint.io/rules/no-floating-promises/
no-floating-promises | typescript-eslint
Require Promise-like statements to be handled appropriately.
Web Dev Cody
Web Dev CodyOP2y ago
forgot about that one, thanks!

Did you find this page helpful?