i.sona
i.sona
CCConvex Community
Created by i.sona on 12/27/2024 in #support-community
using convex-ents mapping feature
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.
10 replies
CCConvex Community
Created by i.sona on 12/12/2024 in #support-community
Error in return types
I am getting the error below
Uncaught Error: Result {"data":"undefined","error":"Unauthorized"}
Uncaught Error: Result {"data":"undefined","error":"Unauthorized"}
when i call a query or a mutation simply because i am returning a Result type
export class Result<T> {
constructor(
public readonly data?: T,
public readonly error?: string
) {}

get isOk(): boolean {
return this.error === undefined
}

static success<T>(data: T): Result<T> {
return new Result(data)
}

static failure<T>(error: Error): Result<T> {
console.log('error', error)
return new Result<T>(undefined, error?.message)
}
}
export class Result<T> {
constructor(
public readonly data?: T,
public readonly error?: string
) {}

get isOk(): boolean {
return this.error === undefined
}

static success<T>(data: T): Result<T> {
return new Result(data)
}

static failure<T>(error: Error): Result<T> {
console.log('error', error)
return new Result<T>(undefined, error?.message)
}
}
i do not want to throw in any case and handle the response in the calling application .
3 replies
CCConvex Community
Created by i.sona on 10/18/2024 in #support-community
Can I use Tanstack Start Without react-query
I wish to know if its possible and Ok to use tanstack-start with Convex directy without react-query . Or is react-query a must for this combo
4 replies
CCConvex Community
Created by i.sona on 9/28/2024 in #support-community
How do i create a schema object with computed fields
using convex.dev and or convex-ents , how do i define a computed field. If i have an entity user defined in my schema with fields first name and last name, how do i define a fullname field that concats first and last name. This is just an example, it can be any computed field
7 replies
CCConvex Community
Created by i.sona on 9/23/2024 in #support-community
convex-auth with sveltekit
Hi Here, While convex references and examples are react-heavy (react-focused) , i want to ask if anyone has been successful in implementing convex-auth with sveltekit , particularly with session validation in server hooks . Thanks
3 replies