Help

Delete Data Daily

1586 5
cancel
Showing results for 
Search instead for 
Did you mean: 
Todd_Robbins
4 - Data Explorer
4 - Data Explorer

Is there a way for tables data to clear at a certain time each day automatically?

5 Replies 5

Sure can, but you'll always need a scripting action to run the deletion.

For a simple table that looks like this;

Karlstens_2-1671137566662.png

We can delete an array of records by using;

deleteRecordsAsync()

The code may look something like this;

 

const {deleteRecordIds} = input.config();
const table = base.getTable("Delete Records");

await table.deleteRecordsAsync(deleteRecordIds);

 

With the input of records to delete array coming from the no-code action "Find Records";

Karlstens_0-1671137475188.png

The Automation can be set to run on a time, find records that meet your deletion criteria, and delete them.

Karlstens_1-1671137520087.png

Deleting records in one big batch has the major advantage of being easily recovered from the trash with one click;

Karlstens_3-1671137687049.png

 

 

The system that @Karlstens wrote will only work if there are less than 50 records to delete. This is due to two issues:

- The "deleteRecordsAsync" function only accepts a maximum of 50 records.

- The "Find Records" action can find a maximum of 100 records.

Instead, if you want a low code solution, I recommend having a filtered view that shows only the records to. be deleted, and then run a script that deletes all the records in the view. A couple of different versions of such a script have been posted on the forums in the past. I am not able to search for them since the change to the new forum platform, but I am on a mobile device. If you are able to search for them, could you please add the link in a reply to this topic? That will help future users who might have the same question.

I can't find the old topic

Philljones22
4 - Data Explorer
4 - Data Explorer

Yes, you can automate the clearing of table data at a specific time each day using various methods depending on your environment. Here are some approaches:

1. **Database-Specific Solutions**:
- **MySQL/MariaDB**: You can use a scheduled event to clear data at a specific time.
```sql
CREATE EVENT clear_table_data
ON SCHEDULE EVERY 1 DAY STARTS '2024-09-04 00:00:00'
DO
DELETE FROM your_table_name;
```
- **PostgreSQL**: You can use a cron job with `psql` or a `pg_cron` extension to schedule a daily task.
```bash
psql -c "DELETE FROM your_table_name;" -U your_user -d your_database
```

2. **Using a Script with Cron Job**:
- You can write a script in Python, Bash, or any preferred language that connects to your database and clears the table.
- Then, schedule this script to run at a specific time every day using `cron` (Linux/Mac) or Task Scheduler (Windows).
```bash
0 0 * * * /path/to/your/script.sh
```

3. **Cloud-Based Solutions**:
- If you're using a cloud database (e.g., AWS RDS, Google Cloud SQL), you can set up a Lambda function or Cloud Function that runs at a specific time each day and executes the required query to clear the data.

4. **Application Logic**:
- If your application is running constantly, you could include logic in your code that triggers a table clear operation at a specific time each day.

Each of these methods allows you to automatically clear table data at a scheduled time, depending on your environment and specific needs.

MichaelHenry05
4 - Data Explorer
4 - Data Explorer

To automatically clear table data at a specific time each day, you can use JavaScript, server-side programming, or database-specific features. JavaScript's setInterval function can be used to trigger a function at regular intervals, while server-side languages like PHP or Python can leverage cron jobs or task schedulers. Databases often provide built-in event schedulers for automated tasks. Remember to consider time zone settings, data retention requirements, and error handling when implementing these solutions. For a more tailored approach, consider using a Nekki-specific solution or API that might offer additional features or integrations.