pilgr / Paper

Paper is a fast NoSQL-like storage for Java/Kotlin objects on Android with automatic schema migration support.
Apache License 2.0
2.35k stars 234 forks source link

How do I delete a specific item from a book? #174

Closed badoyg closed 4 years ago

badoyg commented 4 years ago

How do I delete an item from a book?

For example, I have this code:

List contacts = new ArrayList<>(); contacts.add("one"); contacts.add("two"); contacts.add("three");

    Paper.book().write("contacts", contacts);

How do I delete only "two" from the book afterwards?

pilgr commented 4 years ago

In this case the contacts list has to be modified in memory and then written to the book with the same key. Like so:

contacts.remove(1);
Paper.book().write("contacts", contacts);

People who came with common DB mindset may find this not efficient or weird, but in fact that's way faster and outperforms DBs for common mobile use cases.