convex-js icon indicating copy to clipboard operation
convex-js copied to clipboard

request: add computed values in the db

Open IAlphaOmegaI opened this issue 10 months ago • 0 comments

Pretty much the title, if we could have computed values in the database level, it would make filtering much easier,

Example:

posts: defineTable({
     ratings: v.array(v.number())
}, {

computed: { avarageRating: ({ratings) => ratings.reduce(...) / rating.length ?? 1))}
})


// filtering based on avarageRating would be much easier

await ctx.db
      .query("posts").filter(q => q.gte(q.field("avarageRating"), 3))

...

IAlphaOmegaI avatar Jan 24 '25 10:01 IAlphaOmegaI