abdullahislam_
CCConvex Community
•Created by abdullahislam_ on 7/10/2024 in #support-community
Filter scanning entire table - any alternative to withIndex?
Hi - so I noticed one of my functions is using up a LOT of bandwith on reads, and I think this code is the culprit.
The thing is I need to use an OR statement to search for users where either the email address matches OR the anonId matches.
I don't think I can do this using withIndex, cos it doesn't support u.or()
The only alternative to this I can think of is to run 2 seperate queries:
1. Run a query for just email on using a withIndex("by_email")
2. Run another query for anonId using a withIndex("by_anonId")
Is that the best approach?
RIP my bandwidth for this month 😦
3 replies
CCConvex Community
•Created by abdullahislam_ on 6/29/2024 in #support-community
De-duplicate table with existing values
I have a table that already has data. I want to do a find a remove rows where there's duplicates.
What's the best way to approach this?
6 replies
CCConvex Community
•Created by abdullahislam_ on 2/18/2024 in #support-community
Upsert feature in convex?
HI - is there any plans to introduce a .upsert function in convex?
Currently this is how I'm approaching it:
export const upsertTask = mutation({
args: {
text: v.string(),
},
handler: async (ctx, args) => {
const existingItem = await ctx.db
.query("tasks")
.filter((q) => q.eq(q.field("task_name"), args.text))
.first();
if (existingItem !== null) {
await ctx.db.patch(existingItem._id, {
task_name: args.text,
});
} else {
await ctx.db.insert("tasks", {
task_name: args.text,
isCompleted: false,
});
}
},
});
Which achieves the purporse, but was thinking if there was a better/shorter approach to this?
Thank you
5 replies