Answer the question
In order to leave comments, you need to log in
How to delete an entry in a table after 7 days?
There are records in the Users table.
Each entry can be added at different times.
Each entry can be kept for a maximum of 7 days.
Can I make it so that the record is deleted after this period? (Roughly speaking, assign each entry a field with a timer). I read that you need to use moment, but I can’t figure out how to do it.
Another small question. If it is still possible to do this, will it heavily load the database, let's say, approximately, with 10'000 records?
I am using Sequelize 6.6.2 / PostgreSQL 8.6.0
Answer the question
In order to leave comments, you need to log in
Store the creation date of the record and simply exclude rows that are older than 7 days relative to the query time when fetching.
Another small question. If it is still possible to do this, will it heavily load the database, let's say, approximately, with 10'000 records?
I have never worked with SQL databases, only with MongoDB, and there is such a thing as Time To Life
index, that is, we mark the field with the creation date (UTC format) of this record with the TTL index and set the ExpiresAfrerSeconds parameter (in the week 60 * 60 * 24 * 7 seconds) and as a result, the database will delete this record for us in a week.
I don't know about postgre, but maybe you should read about TTL in your database.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question