DeepakDahiya
DeepakDahiya
CCConvex Community
Created by DeepakDahiya on 8/26/2024 in #support-community
Beyond Performance: Do Indexes Offer Advantages Over Filter Functions?
I've observed that a query like the following:
export const getUserByNameAndEmail = query({
args: {
email: v.string(),
name: v.string(),
},
handler: async (ctx, { email, name }) => {
return await ctx.db
.query("users")
.filter((q) =>
q.and(q.eq(q.field("name"), name), q.eq(q.field("email"), email))
)
.unique();
},
});
export const getUserByNameAndEmail = query({
args: {
email: v.string(),
name: v.string(),
},
handler: async (ctx, { email, name }) => {
return await ctx.db
.query("users")
.filter((q) =>
q.and(q.eq(q.field("name"), name), q.eq(q.field("email"), email))
)
.unique();
},
});
works perfectly fine without needing to create any indexes(index || withIndex). Aside from the performance boost that indexes provide, are there any other potential issues we might encounter by relying solely on the filter function? Could there be situations where using an index is necessary to ensure the query functions correctly?
3 replies
CCConvex Community
Created by DeepakDahiya on 8/24/2024 in #support-community
Default field value
Is there any way to specify default value for a document field (column)
4 replies
CCConvex Community
Created by DeepakDahiya on 8/21/2024 in #support-community
Dynamic table
Is it possible to create dynamic tables in Convex database? I'm building a backend where each user can have their own dedicated 'space' table(for example 'space_userUid'). While the schema would remain consistent across all users, each 'space' table would be unique to the user and would store their notes with columns like title, events, etc. Could you advise on the best approach to implement this?
3 replies