How to use local Sqlite database efficiency in Dart/Flutter
Solution 1
you can try Hive
or Objectbox
. Both of them are local DB that easy to use and also faster than SQFLite
.
If you want to learn more about Hives
, you can learn here
If you want to learn more about Objectbox
, you can learn here
this is the database performance benchmark between Hive
, Objectbox
, and SQFLite
(image source: link)
I have try both hive
and objectbox
. Its recommended for you if you have a complex data and want to solve the storing problem.
Goodluck, hope it helps!
Solution 2
Its better if you use Hive
, its a local DB that will let you solve your complex data problem. Super easy and works much faster than SQflite
Things you need:
- https://pub.dev/packages/hive
- https://pub.dev/packages/hive_flutter
- https://pub.dev/packages/hive_generator
And of course some tutorial as well. So,
Cheers and good luck!
Littlepea
Updated on December 02, 2022Comments
-
Littlepea over 1 year
I'm a newbie in flutter and android application. I have developed a quiz app. It loading a Json data from Firebase and i want to save it to Sqlite(for query fast purpose). My problem is Json data quite complicated, it have multi data array nested(refer Json data as bellow)
Since Sqlite doesn't allow nesting tables within tables, I not sure how to organize or convert the data to Sqlite most reasonable. I am thinking of saving all my Json as a String, but I know it not a good idea. Any have a better idea, very appreciate it
{ "title": "TEST title", "des": null, "ver": 0, "partOne": [ { "number": 1, "correctAns": 3, "question": "question 1 here?", "ansA": "answer A here", "ansB": "answer B here", "ansC": "answer C here", "ansD": "answer D here" }, // about 100 question ... // about 100 part ... ] }
-
Littlepea over 2 yearsHi Hamza, thank for your sharing, I'll try to do it.
-
Littlepea about 2 yearsHi, I tried Hive as Hamza recommended, it seem quite fitting with my project. I'll try objectbox another time. Thank for your sharing.