Monk
Monk11mo ago

inArray or sql in options?

Hello, looking for some guidance on doing a sql in with convex. In drizzle, I am doing something like:
const dbMatchups: Matchup[] = await db.query.matchups.findMany({
where: and(eq(matchups.league, league), inArray(matchups.game_id, gameIds)),
})
const dbMatchups: Matchup[] = await db.query.matchups.findMany({
where: and(eq(matchups.league, league), inArray(matchups.game_id, gameIds)),
})
I'm not seeing a good way to do similar in convex, other than previous suggestions to query all and filter in ts. Is there a way to do something like:

export const getMatchupsByGameIds = query({
args: { gameIds: v.array(v.string()) },
handler: async (ctx, { gameIds }) => {
const matchups = await ctx.db
.query("matchups")
.withIndex("by_active_game_ids", (q) => q.in("game_id", gameIds))
.take(500);
return matchups;
},
});

export const getMatchupsByGameIds = query({
args: { gameIds: v.array(v.string()) },
handler: async (ctx, { gameIds }) => {
const matchups = await ctx.db
.query("matchups")
.withIndex("by_active_game_ids", (q) => q.in("game_id", gameIds))
.take(500);
return matchups;
},
});
thanks!
1 Reply
lee
lee11mo ago
nope that's not possible. you can query for each gameId separately and merge the results. or do the filter in typescript (https://stack.convex.dev/complex-filters-in-convex)
Using TypeScript to Write Complex Query Filters
There’s a new Convex helper to perform generic TypeScript filters, with the same performance as built-in Convex filters, and unlimited potential.

Did you find this page helpful?