TheNinjrKillrT
Convex Community2y ago
3 replies
TheNinjrKillr

Error on 3-expression Index

I've got this model in my schema:
        accounts: defineTable({
            user: v.id('users'),

            type: v.string(),

            provider: v.string(),
            providerAccountID: v.string(),
        })
        .index('by_user', ['user'])
        .index('by_provider', ['provider', 'providerAccountID'])
        .index('by_provider_and_type', ['provider', 'providerAccountID', 'type']),

And this mutation:
export const link = mutation({
    args: {
        account: v.object({
            user: v.id('users'),

            type: v.string(),

            provider: v.string(),
            providerAccountID: v.string(),
        })
    },
    handler: async (ctx, args) => {
        const account = await ctx.db.query('accounts')
                            .withIndex('by_provider_and_type', q => q.eq('provider', args.account.provider)
                                                                        .eq('providerAccountID', args.account.providerAccountID)
                                                                        .eq('type', args.account.type))
                            .first();

        if(!account) return undefined;

        return await ctx.db.patch(account._id, args.account )
    }
});


And I'm getting these two errors:
convex/auth/account.ts:27:40 - error TS2345: Argument of type '"by_provider_and_type"' is not assignable to parameter of type '"by_user" | "by_provider" | "by_creation_time"'.

convex/auth/account.ts:27:109 - error TS2339: Property 'eq' does not exist on type 'IndexRange'.
Anyone have any suggestions?
Was this page helpful?