amplify-android icon indicating copy to clipboard operation
amplify-android copied to clipboard

Deleting items from the database, filtering non-deleted items on Android (Kotlin)

Open flying-mojo opened this issue 1 year ago • 3 comments

Which Specific Feature is your question related to?

Data, model generation

Question

Hi! I have two related questions:

  1. is it possible to completely remove/purge all deleted items from my database either via amplify cli or amplify studio? At the moment when i query the database with graphql queries the returned answer includes all the items that have been deleted. Is it possible to completely remove the deleted items from the database so that they do not appear in any queries?

  2. On node.js / javascript the autogenerated model (generated using amplify codegen models) does include a _deleted property that i can check and filter out all the deleted items. However on Android (Kotlin) the generated model does not have _deleted property, so i can not filter out deleted items. How can i filter out deleted items from my list queries on Android/Kotlin?

Thanks,

flying-mojo avatar Apr 11 '23 19:04 flying-mojo

Hi @flying-mojo - can you please clarify how you're deleting the items? Are you deleting the item through DataStore?

mattcreaser avatar Apr 19 '23 18:04 mattcreaser

Hi @mattcreaser ! No, im using the graphql API: API.graphql(graphqlOperation(deleteOperation,...) or (on android): Amplify.API.mutate(ModelMutation.delete(...)) or sometimes manually through Amplify console content tab.

flying-mojo avatar Apr 21 '23 11:04 flying-mojo

Hey @flying-mojo! Regarding question 1 - it is possible to completely remove deleted items from the underlying datasource which will remove them completely from any response. Here's one way to do this: from Studio you can go to GraphQL API and click on the resource name to open AppSync, then to Data Sources and click on the resource for the particular model to open DynamoDB, Explore Table Items and then select the item and use Actions > Delete Item.

Note that the reason items remain in the table after deletion is to allow other clients an opportunity to sync the deletion. Directly deleting the row could potentially orphan the record in clients that haven't sync'd the delete. You can change the TTL that the record stays in the base table by navigating to the datasource in AppSync as above, and then selecting the datasource and hitting Edit, and changing the value for Base table time to live (TTL in minutes).

I'm still looking in to your second question and will get back to you when I have more information.

mattcreaser avatar May 04 '23 20:05 mattcreaser