I am developing an iOS app that uses sqlite database with the help of FMDB
. I used to work with Core Data
, but it was very slow with 5000 items insert at a time. FMDB
with transactions make such inserts much more faster!
Also I need some mechanism that can notify my view controllers when some items from sqlite table are updated. NSFetchedResultsController
was my solution, but since I use FMDB
I can no longer use NSFetchedResultsController
.
Is there any way to be notified when sqlite tables update?
My advice to you is to revert back to Core Data. You should address the insert performance issue rather than dropping down to the database level and having to revisit all kinds of far more complicated mechanisms of your data model setup. Your specific issue is a case in point.
To optimize the speed of inserts refer to the numerous helpful SOF answers. As has been pointed out, finding the right batch size for your data type is key here.
Regardless of your optimizations, however, you can leverage the Core Data framework to perform these intensive operations in the background. This would not impact the usability of your app, presumably even less than your 0.7 seconds inserts with FMDB.
I have been searching for a while and found a solution. I wonder why I haven't found it earlier.
My choice now is YapDatabase. I don't know about its weaknesses but there are so many great things about this library:
- Regularly updated. Has more then 1000 commits! Wow!
- It's a key/value store. I'm just saving my NSDictionaries. No more data models and headaches.
- Perfomance is great. I have compared to Core Data delete + insert speed.
- And the most great thing is "Views":
Views allow you Sort, Group & Filter your data. Perfect for
tableViews, collectionViews, and more. And they even provide
NSFetchedResultsController style updates to make it easy to animate
changes to your tableViews/collectionViews.