Open maheshkumar2150 opened 4 years ago
Adding one by one. Unlike sqlite, hive doesn't have to parse query, compile it and execute on each insert.
I don't understand. What do you mean by compile it and execute on each insert? I copy data.db during the app installation from sqflite. The data has huge number of records.
One by one coping will take a lot of time. I am using sqflite for just one table of record.
Sorry I misunderstood your question. Hive stores data in init_dir+box_name.hive file. You can pre-generate this file and copy the file as like you did for sqlite db.
Thank you so much. init_dir .. What is the equivalent function in flutter? getApplicationDocumentsDirectory()
Can you please show me a simple code with flutter to copy the data to the right directory
Let me repharse the question (as I'm looking for the similar functionality).
Initialization:
Directory directory = await pathProvider.getApplicationDocumentsDirectory();
Hive.init(directory.path);
Hive.registerAdapter(InventoryAdapter());
Add initial data:
addItem(Inventory item) async {
var box = await Hive.openBox<Inventory>('inventory');
box.put('abc', item);
var data = box.get('abc');
print(data.description); //looks good
}
How to Get Database to use in future? I want to save this initial database in assets folder and will make it part of the build. How can I do it?
@TheMisir is there a way I can download this initial database to my download folder or any other workaround to get this database.
Hi
I use sqflite for flutter app. If I have to use hive db, what are the solution to copy the all the initial data to hive db instead of looping and adding one by one.