i.sona
i.sona3mo ago

.i.sona's Thread

how do i combine map with afilter or getX(index) . something like
const team = ctx
.table('teams')
.get(ctx.viewerX().teamId)
.map((t: Ent<'teams'>) => {
return {
team: t.doc(),
teamLocations: t.edgeX('teamLocations').docs(),
workdaySettings: t.edgeX('workdaySetting').doc(),
calendarBlocks: t
.edgeX('calendarBlocks')
.filter((q: any) => q.gte(q.field('startDate'), Date.now()))
.docs(),
appointmentTypes: t.edgeX('appointmentTypes').docs()
}
})

const team = ctx
.table('teams')
.get(ctx.viewerX().teamId)
.map((t: Ent<'teams'>) => {
return {
team: t.doc(),
teamLocations: t.edgeX('teamLocations').docs(),
workdaySettings: t.edgeX('workdaySetting').doc(),
calendarBlocks: t
.edgeX('calendarBlocks')
.filter((q: any) => q.gte(q.field('startDate'), Date.now()))
.docs(),
appointmentTypes: t.edgeX('appointmentTypes').docs()
}
})

or
const team = await ctx.table('teams')
.filter((q: any) => q.eq(q.field('teamId'), ctx.viewerX().teamId))
.map((t: Ent<'teams'>) => {
return {
team: t.doc(),
teamLocations: t.edgeX('teamLocations').docs(),
workdaySettings: t.edgeX('workdaySetting').doc(),
calendarBlocks: t
.edgeX('calendarBlocks')
.filter((q: any) => q.gte(q.field('startDate'), Date.now()))
.docs(),
appointmentTypes: t.edgeX('appointmentTypes').docs()
}
})
.firstx()
const team = await ctx.table('teams')
.filter((q: any) => q.eq(q.field('teamId'), ctx.viewerX().teamId))
.map((t: Ent<'teams'>) => {
return {
team: t.doc(),
teamLocations: t.edgeX('teamLocations').docs(),
workdaySettings: t.edgeX('workdaySetting').doc(),
calendarBlocks: t
.edgeX('calendarBlocks')
.filter((q: any) => q.gte(q.field('startDate'), Date.now()))
.docs(),
appointmentTypes: t.edgeX('appointmentTypes').docs()
}
})
.firstx()
should be possible , such that the mapping is on a subset of data instead of the whole table being transversed , when there is a very large dataset.
1 Reply
convex-threads
convex-threads3mo ago
Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets. If this is a support question related question please create a post in #support-community. If not, carry on! Thanks

Did you find this page helpful?