Does Payload have trigger functions similar to Supabase, running on every insert/update/delete? I've seen the collection hooks, but I wonder if there's a more database-native way of dealing with this rather than with JS hooks. My use case is to automatically update an aggregate table whenever data/rows have changed in another table.
Payload does not have anything like that at the database level. Since Payload wraps Drizzle, it's theoretically possible for you to write some associated scripts that will achieve this, though.
From your description, it seems like Payload hooks would be able to achieve this easily. What's the reasoning for not wanting to do it that way?
Thanks for the super quick answer! 🙌
I'm very new to Payload so I might not be very familiar with the hooks system.
Two reasons though:
1) Already got the business logic in plpgsql, was interested in whether this could easily be reused in Payload or not, and
2) That Postgres trigger functions (as far as I know) do not require an additional network call, but as far as I can tell this would be the case with using hooks. That's not a biggie, but it introduces another possible point of failure which of course would be nice to avoid if something like trigger functions were available!
1. Understandable if you already have that work done
2. Payload leverages the Local API for hooks, so it isn't necessarily a REST call. Any interactions is direct to DB.
Neat. I'll give it a try! I'm not a big fan of writing plpgsql if I could choose, so it has been more out of necessity. Appreciate the help!
Star
Discord
online
Get dedicated engineering support directly from the Payload team.