Tiger πŸ…
Tiger πŸ…β€’4w ago

> Convex supports indexes containing up

Convex supports indexes containing up to 16 fields. You can define 32 indexes on each table. Indexes can't contain duplicate fields.
tried three fields, been battling with typescript for more than an hour gonna continue tomrorow strange, never had issues with convex indexes i wonder if anyone else has succeeded with more than 2 index fields for an index?
34 Replies
erquhart
erquhartβ€’4w ago
What's happening? I have lots of indexes with lots of fields, what error(s) are you seeing? also Tiger how do you not have more than two fields in your indexes, you are not convexing hard enough lol
MapleLeaf 🍁
MapleLeaf πŸβ€’4w ago
it's a typescript issue? so it may be a problem with the index definition itself, can you show your schema code?
Tiger πŸ…
Tiger πŸ…OPβ€’4w ago
@MapleLeaf 🍁 @erquhart yeah sorry for not being specific its typescript complaining
Function implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.
Function implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.
guess i gotta convex harder lmfao i tried just focusing on one mutation, commenting the others out trying to narrow this down
export const getFlameProgress = query({
args: {
flame: convexFlameUnionSchema,
},
handler: async (ctx, args) => {
const user = await ctx.runQuery(api.users.currentUser)
if (!user) throw new ConvexError('User not found')

// return ctx.db
// .query('flameProgress')
// .withIndex('by_userId_flame_lang', (q) =>
// q.eq('userId', user._id).eq('flame', args.flame).eq('lang', user.lang)
// )
// .unique()
},
})
export const getFlameProgress = query({
args: {
flame: convexFlameUnionSchema,
},
handler: async (ctx, args) => {
const user = await ctx.runQuery(api.users.currentUser)
if (!user) throw new ConvexError('User not found')

// return ctx.db
// .query('flameProgress')
// .withIndex('by_userId_flame_lang', (q) =>
// q.eq('userId', user._id).eq('flame', args.flame).eq('lang', user.lang)
// )
// .unique()
},
})
when i comment in getting the flame progress user loses its type defintiions as if everything messus up
Tiger πŸ…
Tiger πŸ…OPβ€’4w ago
https://www.youtube.com/watch?v=6H-PLF2CR18 sunday morning noth feels better than blasting lofi at full volume
LOFI KEEP YOU SAFE
YouTube
Breathe πŸ€ Lofi Deep Focus 🌳 Study/Calm/Heal [ Lofi Hip Hop - Lofi C...
Breathe πŸ€ Lofi Deep Focus 🌳 Study/Calm/Heal [ Lofi Hip Hop - Lofi Chill ] ---------------------------------------- ➀ Subscribe to LOFI KEEP YOU SAFE: https://www.youtube.com/channel/UCwqMCMwQrzGMSZ-jpZqAs6A I'm fleece. Hope your day is as motivating as this mix! Subscribe to my channel to get notified when new videos are released. Peace! Foll...
Tiger πŸ…
Tiger πŸ…OPβ€’4w ago
only thing missing is the morning coffee but lemme get in some water first
erquhart
erquhartβ€’4w ago
When you run a function from within another function you have to explicitly type any part of the return value that came from the inner function.
Tiger πŸ…
Tiger πŸ…OPβ€’4w ago
also big cleaned myroom this morning feels so fucking good clean room + good music + write loads of code no way
erquhart
erquhartβ€’4w ago
Actions | Convex Developer Hub
Actions can call third party services to do things such as processing a payment
Tiger πŸ…
Tiger πŸ…OPβ€’4w ago
i see
erquhart
erquhartβ€’4w ago
Used to only affect actions but now that any function can run other functions it can happen to any of them
Tiger πŸ…
Tiger πŸ…OPβ€’4w ago
ERQUAHARTTTT ty virtual dap my G thanks so much hahaha
handler: async (ctx, args) => {
const user: DataModel['users']['document'] | null = await ctx.runQuery(
api.users.currentUser
)
if (!user) throw new ConvexError('User not found')

return ctx.db
.query('flameProgress')
.withIndex('by_userId_flame_lang', (q) =>
q.eq('userId', user._id).eq('flame', args.flame).eq('lang', user.lang)
)
.unique()
},
handler: async (ctx, args) => {
const user: DataModel['users']['document'] | null = await ctx.runQuery(
api.users.currentUser
)
if (!user) throw new ConvexError('User not found')

return ctx.db
.query('flameProgress')
.withIndex('by_userId_flame_lang', (q) =>
q.eq('userId', user._id).eq('flame', args.flame).eq('lang', user.lang)
)
.unique()
},
but then this should work no πŸ€” @erquhart still doesnt work 😭 the schema @MapleLeaf 🍁
flameProgress: defineTable({
userId: v.id('users'),
// flame is the difficulty of the world
flame: convexFlameUnionSchema,
lang: v.union(v.literal('en'), v.literal('de')),
isUnlocked: v.boolean(),
rankCounts: convexRankCountsSchema,
totalWorldsCount: v.number(),
}).index('by_userId_flame_lang', ['userId', 'flame', 'lang']),
flameProgress: defineTable({
userId: v.id('users'),
// flame is the difficulty of the world
flame: convexFlameUnionSchema,
lang: v.union(v.literal('en'), v.literal('de')),
isUnlocked: v.boolean(),
rankCounts: convexRankCountsSchema,
totalWorldsCount: v.number(),
}).index('by_userId_flame_lang', ['userId', 'flame', 'lang']),
full current query
export const getFlameProgress = query({
args: {
flame: convexFlameUnionSchema,
},
handler: async (ctx, args) => {
const user: DataModel['users']['document'] | null = await ctx.runQuery(
api.users.currentUser
)
if (!user) throw new ConvexError('User not found')

return ctx.db
.query('flameProgress')
.withIndex('by_userId_flame_lang', (q) =>
q.eq('userId', user._id).eq('flame', args.flame).eq('lang', user.lang)
)
.unique()
},
})
export const getFlameProgress = query({
args: {
flame: convexFlameUnionSchema,
},
handler: async (ctx, args) => {
const user: DataModel['users']['document'] | null = await ctx.runQuery(
api.users.currentUser
)
if (!user) throw new ConvexError('User not found')

return ctx.db
.query('flameProgress')
.withIndex('by_userId_flame_lang', (q) =>
q.eq('userId', user._id).eq('flame', args.flame).eq('lang', user.lang)
)
.unique()
},
})
MapleLeaf 🍁
MapleLeaf πŸβ€’4w ago
what's convexFlameUnionSchema?
erquhart
erquhartβ€’4w ago
That’s still leaning on inference
MapleLeaf 🍁
MapleLeaf πŸβ€’4w ago
that seems potentially relevant oh wait oh no yeah i see what erquhart means lol
Tiger πŸ…
Tiger πŸ…OPβ€’4w ago
what am i missing
MapleLeaf 🍁
MapleLeaf πŸβ€’4w ago
const user: DataModel['users']['document'] | null that's the issue
Tiger πŸ…
Tiger πŸ…OPβ€’4w ago
shouldnt that be ok
MapleLeaf 🍁
MapleLeaf πŸβ€’4w ago
does it work if you remove it? but also why is that there
Tiger πŸ…
Tiger πŸ…OPβ€’4w ago
type annotation to work around the inference issue
Tiger πŸ…
Tiger πŸ…OPβ€’4w ago
Actions | Convex Developer Hub
Actions can call third party services to do things such as processing a payment
MapleLeaf 🍁
MapleLeaf πŸβ€’4w ago
oh :ded: maybe put an annotation on the currentUser query instead? the return type probably
erquhart
erquhartβ€’4w ago
I can’t remember if this works but try typing that return value as Doc<β€˜flameProgress’>
MapleLeaf 🍁
MapleLeaf πŸβ€’4w ago
issues like this are kind of just a guess lol
erquhart
erquhartβ€’4w ago
Might still be in the inference loop
Tiger πŸ…
Tiger πŸ…OPβ€’4w ago
🀧
export const getFlameProgress = query({
args: {
flame: convexFlameUnionSchema,
},
handler: async (ctx, args) => {
const user = (await ctx.runQuery(api.users.currentUser)) as Doc<'users'>
if (!user) throw new ConvexError('User not found')

return ctx.db
.query('flameProgress')
.withIndex('by_userId_flame_lang', (q) =>
q.eq('userId', user._id).eq('flame', args.flame).eq('lang', user.lang)
)
.unique()
},
})
export const getFlameProgress = query({
args: {
flame: convexFlameUnionSchema,
},
handler: async (ctx, args) => {
const user = (await ctx.runQuery(api.users.currentUser)) as Doc<'users'>
if (!user) throw new ConvexError('User not found')

return ctx.db
.query('flameProgress')
.withIndex('by_userId_flame_lang', (q) =>
q.eq('userId', user._id).eq('flame', args.flame).eq('lang', user.lang)
)
.unique()
},
})
this gets the job done cheers love you all gonna add a code comment here so my future self doesn't get all confused
MapleLeaf 🍁
MapleLeaf πŸβ€’4w ago
fair enough
Tiger πŸ…
Tiger πŸ…OPβ€’4w ago
when ure evil enough to think
MapleLeaf 🍁
MapleLeaf πŸβ€’4w ago
fwiw this might be why I tend to prefer having functions (like getCurrentUser(ctx)) to reuse functionality
Tiger πŸ…
Tiger πŸ…OPβ€’4w ago
its time for me to writer a post why not to use convex
Tiger πŸ…
Tiger πŸ…OPβ€’4w ago
🀣 justk idding whata fucking dickhead i wouldve been lmfao
MapleLeaf 🍁
MapleLeaf πŸβ€’4w ago
i mean hey if it has valid criticisms, the convex team would still appreciate it πŸ˜›
Tiger πŸ…
Tiger πŸ…OPβ€’4w ago
yeah, but i guess this is some quriky ts issue 😭 thats better actually when i think about it hmmh much cleaner love it

Did you find this page helpful?