_modifiedTime
We automatically get a _creationTime field on tables, but I would like to also have a created by, modified by, and modified time field on all my tables.
Is there a best way to approach this in Convex?
I don't mind adding boiler plate for this each time I make a table, I just want to avoid manually updating them any time I mutate a table.
Would triggers be the best approach here?
(Thanks for any advice y'all might give. 🌟 )

3 Replies
You could probably set up triggers https://stack.convex.dev/triggers to do this. You'd have to define a trigger for each table, but if your logic is the same across all tables you could write a reusable function and just call it in every trigger 🙂
Database Triggers
Triggers automatically run code whenever data in a table changes. A library in the convex-helpers npm package allows you to attach trigger functions t...
I don't know why I didn't think about re using a function inside the trigger definitions.
That helps get rid of most of the "ick" i had around copying and pasting logic with the triggers approach.
I'll run with this approach, thanks!
yeah youll still need to do some boilerplate as you outlined originally as well, but it shouldnt be too bad 🙂 for defining your custom fields on every table: you could also write some reusable logic for this, just like convex-helpers has a
systemFields
variable, you could create your own reusable customSystemFields
or whatever that contains your _modifiedTime etc., and just remember to pass this to the schema definition (defineTable
or Table
from convex-helpers). or maybe write your own createTable
wrapper/helper to encapsulate this logic!