Set dynamic key in v.object inside database schema
Hello, is it possible to set a dynamic object key inside the schema? Use case: I have an object which stores metada of each element, it looks like
{ [elementId: string]: {....some data} }
6 Replies
Hey, not yet, we'll likely add a v.record for this in the future. For now the best work around is:
v.array(v.object({key: string, value: ....}))
or use v.any()
and rely on TypeScript for now.Thank you! Gonna try 🙂
looking forward to v.record @Michal Srb
we hear you! I want this too
me too, but just because i think its cool
lol
for anyone finding this thread,
v.record
exists now https://docs.convex.dev/database/schemas#record-objectsSchemas | Convex Developer Hub
Schema validation keeps your Convex data neat and tidy. It also gives you end-to-end TypeScript type safety!