Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List Persistance #6

Closed
Pertempto opened this issue Feb 3, 2023 · 5 comments · Fixed by #11
Closed

List Persistance #6

Pertempto opened this issue Feb 3, 2023 · 5 comments · Fixed by #11
Assignees

Comments

@Pertempto
Copy link
Owner

Currently, if the user closes the app, they lose their list. When they open the app again, they are presented with an empty list.

Implement some form of data persistence, so that the data is saved to the device. When the user opens the app, all their items should still exist.

Be sure to think ahead in your approach. In the future, we will want users to have the ability to create multiple lists. Be sure that your data persistence approach will easily support storing multiple lists

@Pertempto
Copy link
Owner Author

@tycebrown Before you start on the code for this one, we need a good plan for how you will handle data persistence. Do some research and report back on any libraries or approaches you think will work well for this app.

@Pertempto
Copy link
Owner Author

@tycebrown I am curious. Have you done any research for this?

@tycebrown
Copy link
Collaborator

Not much.

I looked at a few options (pretty much Hive and shared_preferences), but not too in-depth.

@tycebrown
Copy link
Collaborator

Alright Mr. Emig, I did some research on the different forms of persistent storage.

TL;DR: I think it would be best/easiest to use one of the following databases: Isar, Hive, and ObjectBox. They all seem about equal.

A database seems like a better choice to me than a file, since our data is somewhat structured, but I'm open.

There are two major types of databases I found: SQL (relational) and NoSQL (non-relational). From my research:

  • A relational database puts data in tables, organized into rows and columns (often, rows represent different objects and columns represent different members of those objects).
  • A relational database is meant to capture meaningful and complex relationships between data.
  • It is typically slower than non-relational data.
  • Finally, it prioritizes data consistency, meaning that reads always obtain the latest value of a record.
  • On the other hand, non-relational databases are faster, more scalable, and more flexible.
  • Non-relational databases don't capture the same meaningful relationships that SQL does. However, some (such as Isar and ObjectBox) allow you to add relational "links."
  • Some non-relational databases prioritize consistency (like ObjectBox) and others (like Hive) prioritize availability, which allows for faster reads (according to my research).

From these, it seems that non-relational data is preferable. It is faster, and it doesn't seem we would need complex relationships. I imagine the most complex relationship between different lists would be their categories.

Among non-relational databases, there were three main competitors I found: Isar, ObjectBox, and Hive. The benchmarks I found were all wildly inconsistent.

Hive is simpler and uses a cache, giving near-instant reads. Isar seems more complex, but is still very fast. In Isar and ObjectBox, relational links can be made between objects. Both provide functions to make complex queries on the data and prioritize consistency over availability.

I am leaning toward Hive just because it looks simpler and easier, but, since Dart objects are large, according to this issue here, the cache might hit RAM limits relatively fast. I'm not sure how much this would be a problem, since closing a box will clear its cache.

@Pertempto
Copy link
Owner Author

@tycebrown Thanks for the detailed write up! Hive sounds like a good option, but the first thing that caught my eye in it's README file was:

Consider using Isar, a Flutter database by the author of Hive that is superior in every way!

This seems to tell me that even the authors of Hive don't recommend using it, but prefer Isar. I would say use either Isar or Hive.

Extra note: in the future, include links in your post to make it easier to find the Github repos for the projects you referenced. For example: Hive, Isar, and ObjectBox.

@tycebrown tycebrown linked a pull request Feb 22, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants