I have field 'Timer' and 'Name' in a Table. I want to set it up as when a row is added to that table. The row should autodelete after the timer runs out. How can I set it up? I'm using Hasura as my GraphQL client and having a React Application?
-
Please share what you have attempted so far. Wouldn't a basic `setTimeOut` and a delete mutation help? – tsamridh86 Nov 27 '20 at 09:58
-
How does setTimeOut work? How does my Name column knows that it has to autodelete after the Timer runs out. Should I also keep a created_at field to keep track of the timer? – KillMe Nov 27 '20 at 10:16
-
Can I do it in my graphql client itself? – KillMe Nov 27 '20 at 10:17
-
You will need to explain more in your question, answering that with only this much information could lead to incorrect results / bad decisions. – tsamridh86 Nov 28 '20 at 12:13
1 Answers
First, instead of timer
you may want to go with something like expires
as you can have 1 field to track this functionality. If you have a created_at
anyway, there is no real functional difference.
You have two main options here.
1: you can have a Hasura cron trigger that fires every X amount of time and checks for now()
> expires
(or > created_at + timer
etc...) and deletes those. You will have to write some code somewhere to run when this webhook is called. This can be a good serverless use case. There are examples and codegen tools. See more in the docs.
2: you can track a view with a where
clause that checks this condition. This won't actually delete the records from your db. But the view with work as though you did delete. This may be a good thing or a bad thing depending on your needs...

- 1,771
- 6
- 12