i.sona
i.sona3mo ago

How do i create a schema object with computed fields

using convex.dev and or convex-ents , how do i define a computed field. If i have an entity user defined in my schema with fields first name and last name, how do i define a fullname field that concats first and last name. This is just an example, it can be any computed field
5 Replies
Convex Bot
Convex Bot3mo ago
Thanks for posting in <#1088161997662724167>. Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets. - Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.) - Use search.convex.dev to search Docs, Stack, and Discord all at once. - Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI. - Avoid tagging staff unless specifically instructed. Thank you!
erquhart
erquhart3mo ago
However you like - Convex makes Typescript your query language, so the equivalent of a fullName computed field in a traditional db would be concatenating those two strings in a Convex function. If you want to avoid manually adding the property everytime you query the table, write a reusable helper that does it for you.
Matt Luo
Matt Luo3mo ago
Yes, in my understanding, the useQuery() is the Convex approach to a traditional database view
Clever Tagline
Clever Tagline3mo ago
To directly answer your question, Convex doesn't have the concept of a "computed field" like some other services provide (e.g. Airtable and its many computed fields: formula, lookup, rollup, etc.). Convex fields only store data. As the others have said, it's up to you to code computations on field data in your app.
i.sona
i.sonaOP3mo ago
to the point. Thanks

Did you find this page helpful?