amplify-android
amplify-android copied to clipboard
Deleting items from the database, filtering non-deleted items on Android (Kotlin)
Which Specific Feature is your question related to?
Data, model generation
Question
Hi! I have two related questions:
-
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?
-
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,
Hi @flying-mojo - can you please clarify how you're deleting the items? Are you deleting the item through DataStore?
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.
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.