Is it possible to delete all records from one database with one click?

I want to be able to delete all records, created in appgyver database with clicking on one trash icon. Is this possible?

1 Like

Yes, it’s possible to create such logic. But not with just one call to backend. You need to create logic that loops through all records in the database and deletes those one-by-one.

  • First use Get record collection to get all records in the database and save those IDs to a variable (e.g. Page variable)
  • Then use Delete record with ID from the just saved (Page) variable (e.g. PICK_ITEM(pageVars.all_ids, 0)
  • Then Set (page) variable again, but without the ID that was just deleted (Formula WITHOUT_ITEM should work well)
  • Then use If condition to check if the (Page) variable isn’t empty yet
  • If it’s not empty, loop back to the same Delete record which will now select another ID of a resource to be deleted from backend

This loop should continue until it has looped through all records in the database

Hi Tomi,
thanks for your answer. I am also looking for exactly this delete function.
As new user, it is not easy to understand.
Is it possible to do a very easy video of what you wrote? Because i really dont know, where to put the “pick_item” and other things into:… sorry for being fool but on the one hand appgyver is really easy and on the other side you expact learning “appgyver language”

It also depends how your data is stored. Firebase stores data in a tree structure, so Deleting a top Node will delete everything below it. You could effectively delete the entire database with just 1 Delete call to the top-most Node

2 Likes

I’m using the AppGyver database. I don’t know how it is stored. I will try the thing that Tomi_Laakso wrote.

If you got it to work, please let me know…i am not shure how it works properly…

I’ve got some error.
PICK_ITEM(pageVars.UsernameDeletion, 0) shows this error:

Object Type is not assignable to text type

And what do i have to write into the item part of this?
WITHOUT_ITEM(pageVars.UsernameDeletion, item)

Hast du es zum Laufen bekommen?

No, we’ll need to wait for an answer.

Dear, this error because of u set ur pageVars.UsernameDeletion as a List of objects.

Here the detail instruction for u :

  1. Set the pageVars.UsernameDeletion as List of text

  2. Create a Data Variables from the Data resource ( if u still didn’t have one ). For example: “username1” from ur data resoure “username”. ( The full name for that Data variables now will be “data.username1” )

  3. Logic : Component tab => Set page variables => Name variable : UsernameDeletion => Assigned Value : use this formula PLUCK(data.username1, “id”) to get all objects id from ur data username as a list of text ( because id is just text type ).

  4. Now u can start Delete Record one by one :
    Resource name : username
    ID : use this formula : PICK_ITEM(pageVars.UsernameDeletion, 0)

Let me know if u need more instruction, because it was 12 days ago, so I’m not sure if it’s still helpful for u or not…

Thanks. This part works. But what do i have to do, to repeat this to delete all data?
Tomi said i have to set this pageVars after with WITHOUT_ITEM(pageVars.UsernameDeletion, item).
But what do i have to write into “item”?

Ok here the next instruction for u :

  1. Set the pageVars.UsernameDeletion as List of text

  2. Create a Data Variables from the Data resource ( if u still didn’t have one ). For example: “username1” from ur data resoure “username”. ( The full name for that Data variables now will be “data.username1” )

  3. Logic : Component tab => Set page variables => Name variable : UsernameDeletion => Assigned Value : use this formula PLUCK(data.username1, “id”) to get all objects id from ur data username as a list of text ( because id is just text type ).

  4. Now u can start Delete Record one by one :
    Resource name : username
    ID : use this formula : PICK_ITEM(pageVars.UsernameDeletion, 0)

  1. After delete first record => Set Page Variable => Name variable : UsernameDeletion
    Assigned Value : WITHOUT_ITEM (pageVars.UsernameDeletion, PICK_ITEM(pageVars.UsernameDeletion, 0)

  2. Add a IF Condition to the logic flows as in picture I attached : COUNT(data.UsernameDeletion) == 0

5 Likes

This works. Thanks…

can you do a video so i can fully understand

I want to delete all my records, not with 1 click, but each time a page is mounted. I want to automatically reset my collection of data records when someone opens the page. So I put this logic after the event “page mounted” of my concerned page, but it doesn’t work… I guess there is a conflict with the logic of the collection of data, but I don’t know what to do exactly. Someone can help me please?

What you want to do is instead of sending a DELETE request multiple times you just POST or PUT an empty record at the top level.

Sorry If I am mistaken, but can’t you just set an if statement checking if the COUNT of your database is egal to zero and if not run a delete record with yourDataBase[0].id as id and loop that ? this way, you check if your database is empty and if not, you delete the item in position 1 (which is position 0 in index) and so on until it is empty.

+1 for a ‘Delete Table’ flow function (AKA client side storage).

I mean we built our own once, but I think this should be a standard like update/replace/delete record.

I have actually put this through as a feature request, but I don’t know that the AppGyver team monitor that part of the site…

2 Likes

This works but not all the time. Sometimes records are still left over in the database. Is there anyway to make sure everything gets deleted.

I managed to do that through a looped function and assigning to a page variable the number of elements in your DB. You then assign this page variable to the index of the delete entry logic function and loop using -1 on this variable until the database is left with no data.

So let’s say you have 20 entries.

You assign the .length of your db to the the “count” variable and it is 20.
You run delete record with 20 as in the index.
You thus delete the last entry (21th)
Then you substract 1 giving you 19.
You loop back to the delete record but now “count” is 19 so you delete the 20th
You get back to substract -1, etc.
You finish by a formula saying if the length of the db is 0, you trigger a message saying “records deleted” or something.