#using convex-ents mapping feature

9 messages · Page 1 of 1 (latest)

harsh grotto
#

how do i combine map with afilter or getX(index) . something like

                .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()

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.

buoyant ferryBOT
#

Thanks for posting in #1088161997662724167.
Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets.

    - Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.)
    - Use [search.convex.dev](https://search.convex.dev) to search Docs, Stack, and Discord all at once.
    - Additionally, you can post your questions in the Convex Community's #1228095053885476985 channel to receive a response from AI.
    - Avoid tagging staff unless specifically instructed.

    Thank you!
muted dagger
harsh grotto
#

I want to stick to convex-ents, the question is related to convex-ents

muted dagger
#

That right sidebar in the docs there has lots of ents methods to browse through for different use cases.

whole hill
harsh grotto
#

I am aware of Al the suggested but none of them answers the question. In a map I can build an abitrary type based on relationship , but with a map in convex-ents you can’t narrow the table scans with an index or a filter , it only applies to all entities in a table. You only apply everything else after the fact which in itself like filter becomes costly as data grows . I should be able to map on an index and attach related data (like a join) in one transaction. I guess convex needs sdks like Kysely or even genql (best lib I know of ontop of graphql)

whole hill