kamilgadek / to_do_list_kamilg

1 stars 0 forks source link

[research] Local storage database: suggest package #31

Closed mszakacz closed 2 months ago

mszakacz commented 2 months ago

We made a decision to store our tasks locally in the device memory. For that we need a package that we will use.

@kamilgadek do a research work and present here few packages that we can use for Local Storage. Please present at least 4-5 and shortly describe and explain what's your choice.

kamilgadek commented 2 months ago
  1. Hive Description: Hive is a lightweight and fast key-value database written in pure Dart, specifically designed for Flutter apps. It supports complex objects, which means you can store your Task objects directly without needing to serialize them manually. Features: No native dependencies, so it works on all platforms. Built-in support for TypeAdapters, which makes it easy to persist Dart objects. Very fast read/write operations. Lazy loading, so it loads only the required data. Supports encryption for secure data storage. Best for: Developers looking for a fast, efficient, and easy-to-use local storage solution, especially for smaller projects. Choice Consideration: Hive is a top choice for this type of application due to its speed, simplicity, and ability to handle complex data models like tasks directly.

  2. SharedPreferences Description: SharedPreferences is a key-value storage mechanism that is part of the Android SDK but has been ported to Flutter. It is mainly used for storing small amounts of primitive data (strings, ints, etc.). Features: Simple API for saving and retrieving primitive types (bool, int, double, String, List). Persistent data across app restarts. Good for small amounts of data like app preferences or settings. Best for: Storing small, simple key-value pairs. Not ideal for storing complex objects like task lists. Choice Consideration: While SharedPreferences is very simple to use, it's not the best option for storing structured or complex data like a list of Task objects.

  3. Moor (Drift) Description: Moor (now known as Drift) is an ORM (Object Relational Mapper) for SQLite in Flutter. It allows you to define SQL tables in Dart and provides a high-level API for database operations. It supports relationships between tables and complex queries. Features: Full control over SQLite features, including transactions, joins, and queries. Automatically generates code for database interactions. Supports reactive streams, which can help in making your UI reactive to database changes. Good performance, as it uses the native SQLite engine. Best for: Apps with complex data structures or those requiring advanced querying capabilities. Choice Consideration: If you foresee needing complex relational data or the ability to run queries, Moor/Drift is a good option. It’s more complex to set up compared to Hive, but very powerful.

  4. SQLite (sqflite) Description: Sqflite is a Flutter plugin for SQLite, which provides a powerful database engine. It’s more traditional than Hive and SharedPreferences, and allows you to run raw SQL queries to manage your database. Features: Full SQL support. Ability to handle complex data relationships. Manual control over database structure and queries. Best for: Apps that require a robust relational database for handling larger datasets or complex queries. Choice Consideration: Sqflite is a good option if you’re comfortable with writing SQL and need the full control it offers. However, it requires more boilerplate compared to other options like Hive.

  5. ObjectBox Description: ObjectBox is a NoSQL database designed for high-performance local storage, providing a fast and efficient way to store Dart objects. Features: High-performance database engine. Simple API to store Dart objects without worrying about SQL. Support for reactive streams. Built-in support for synchronization (in case you want to scale to cloud-based storage later). Best for: Developers looking for a high-performance, NoSQL alternative to SQLite for complex object storage. Choice Consideration: ObjectBox offers great performance and is easy to use with Dart objects, but it may have more features than necessary for a simple to-do app.

My Recommendation: For our simple to-do app, I would recommend using Hive. Here's why:

Ease of Use: Hive is easy to set up and use, especially if we're dealing with storing simple objects like tasks. Performance: It is very fast and lightweight, making it perfect for small to medium-sized apps like a to-do list. Object Storage: Hive can store complex objects directly, which is great for storing your Task class without needing to serialize or manage SQLite tables.

mszakacz commented 2 months ago

@kamilgadek Nice research! Indeed, hive was a great package. However, have you noticed when was the last release? https://pub.dev/packages/hive_flutter - 3 years ago. We don't want to use outdated packages as it means that we would need to use other packages that are outdated. As we start new project, we want to use the newest FLutter version (currently 3.24.3), old package may not work on the newest FLutter version. That is why it's so dangerous.

Please check: sqf lite and give me a comperison. It does not offer so much as hive, but it's stable and up-to-date.

kamilgadek commented 2 months ago

I make a little research and here is why sqf lite packages is perfect for our to do list app: The sflite package is a powerful SQLite database plugin for Flutter, designed to provide efficient and reliable data storage solutions for your mobile applications. It offers a simple and intuitive API, making it easy to integrate into your Flutter projects.

Here are some of the key reasons why sflite is a great choice for your Flutter app development:

  1. Efficiency:

Native SQLite: sflite leverages the native SQLite database engine, ensuring optimal performance and speed for your data operations. Optimized queries: The package provides tools to optimize your SQL queries, reducing execution time and improving overall app responsiveness.

  1. Ease of Use:

Simple API: sflite offers a straightforward API that is easy to learn and use, even for developers new to database management. Asynchronous operations: The package supports asynchronous operations, allowing you to perform database tasks without blocking the UI thread and maintaining a smooth user experience.

  1. Flexibility:

Customizable schema: You can define your own database schema to suit your specific data requirements. Various data types: sflite supports a wide range of data types, including integers, floating-point numbers, strings, blobs, and more. Transactions: The package provides transaction support for ensuring data integrity and preventing inconsistencies.

  1. Cross-Platform Compatibility:

Flutter's nature: As a Flutter plugin, sflite is compatible with both iOS and Android platforms, allowing you to create cross-platform apps without worrying about platform-specific database implementations.

  1. Active Community and Support:

Large user base: sflite has a large and active community of developers, providing valuable resources, tutorials, and support. Regular updates: The package is actively maintained and receives regular updates to address issues and introduce new features. In conclusion, sflite is a versatile and efficient database solution for Flutter apps. Its ease of use, performance, and cross-platform compatibility make it an excellent choice for developers looking to store and manage data in their mobile applications.

mszakacz commented 2 months ago

So one of the disadvantages of sgflite is its relatively higher learning curve. But let's try it. Next Issues will contain development work with use of sqflite