I am building an application for iOS that has to be able to run offline and able to hold a number of tables, but also being to retrieve data easily. Which local database option would be more beneficial to a React Native beginner?
2 Answers
I know this question is already one year old, but I hope this helps someone. The database selection depends on the amount of data you are going to keep, PostgreSQL is out of the question and SQLite is quite good with local databases but it might be a pain to parse all your data into something SQLite can comprehend. Because of this, React Native has multiple ways of doing local storage (like AsyncStorage and LocalStorage), but for a beginner I would recommend other libraries to play with those resources:
redux-persist: If you are using redux, this library can be perfect for you, because with the
autoRehydratationfeature, you don't have to worry about anything but the initial setup. This library will save all your store as it is inside the mobile. You can setup which reducers to blacklist or whitelist, or even program some more advanced features for optimization.Realm: Quite an awesome library, and my personal favorite. It allows you to manage models and queries, with which it will insert or select data inside a local database. It is really fast and has some nifty tricks to improve the
ListViews performance. It can be used alongsideredux-persist, because your database elements won't be saved inside the store.
Both libraries are excellent and I am sure there are even more out there, but I have only tried those two. I recommend you to read Tackling React Native Storage by Eric Kim, so you meet some really useful concepts, code examples and other libraries involving local storage.
Comments
I'm not actually even sure if PostGreSQL is an option (I found zero components). If you have information on how to use this on RN, please share.
As far as I'm aware, SQLite is the man! There are several options here... https://react.parts/native?search=sqlite
RocksDB may also be an option. I've seen some use of that lately, but I think it's mainly just an abstraction for AsyncStorage. I could totally be wrong here as I've not looked to deeply into it. https://gist.github.com/sahrens/ae3ad0889c608ecd51aa