0

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 2

4

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 autoRehydratation feature, 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 alongside redux-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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

2 Comments

A developer friend is looking into using PostGreSQL, so if he finds anything I'll link it, it just seemed an option so I was wondering wether anyone else had encountered it. In terms of SQLite, would that allow me to save a complex database locally? I'd ideally like to be able to save the entire DB locally and then on a button click, sync online. I'm struggling finding good tutorials or links/docs. Would Firebase work allowing to save locally and then sync online?
Yes, firebase will work now firebase.com/blog/2015-05-29-react-native.html. CouchDB is another option. If you use Sqlite, you'll have to roll your own sync engine is believe, which is not trivial. Firebase is probably your best option if you're okay going with NoSQL

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.