18

I'm new to react native and I need a list of local database tools that will meet the minimum criteria in the description to follow.

If this were a PHP/MySQL application, I build 3 database tables:

t_food (500 rows)
- food_id (primary_key)
- food_name (string)

t_meal (100 000 rows)
- meal_id (primary_key)
- meal_name (string)

t_meal_item (1 000 000 rows)
- meal_id (foreign_key)
- food_id (foreign_key)

These three tables combined in MySQL takes up about 10MB to 15MB. Then I would use PHP to create an interface that will present the results of this query:

SELECT meal_id FROM t_meal_item WHERE food_id = @food1 AND meal_id IN (SELECT meal_id FROM t_meal_item WHERE food_id = @food2 AND meal_id IN (SELECT meal_id FROM t_meal_item WHERE food_id = @food3))

In a MySQL/PHP application, the results of the SQL query will return in less than 2 seconds.

In the react-native world, I need a local database that achieves similar results to above but must also comply with the following requirements:

  1. must support 15 MB of persistent storage (so that you can use it without internet access)

  2. querying for a meal filtered by 3 food items must complete in less than 3 seconds on modern mainstream mobile devices. Eg. the equivalent of the SQL query above must complete in less than 3 seconds on an iphone 6 and Huawei Nova Plus.

I have already tried the following:

A. Realm is failing on criteria 2 as indicated in this question here:

Improve the speed of a realm query in react-native?

A solution to the Realm question will be an acceptable answer to this question.

B. Six years ago, I tried this with core data on an iOS device. The iOS device kept crashing due to insufficient memory.

C. I'm trying SQLite Storage but already running into this problem here:

basic React Native SQLite script returning undefined which causes error

What tools can solve this problem?

10
  • How can I improve the quality of the question such that I don't get close or down votes? I'm simply asking what are tools normally meant to solve the problem i'm asking. My problem should be pretty common that there are common approaches to this, as opposed to anything controversial Commented Sep 20, 2017 at 17:36
  • I did not downvoted your question or flagged it but I thought it because answer of this question is very much opinion based since every developer has a different approach on data. You have really a lot of choice since you can go with online database like Firebase or Realm (can work offline too) or a traditional like database like SQLlite or even with a static array of data inserted within the app itself. Every each of them has a positive and a negative side and choosing one is pretty much developer's preference. Commented Sep 20, 2017 at 18:36
  • @bennygenel thanks that's what i'm looking for, a list of common tools used to solve problem. Do you konw from experience if the amount of data I'm dealing with will be a problem? Five years ago, i remember I had performance issues on native iOS trying to deal with a million records in t_meal_item when stored in the iOS model system. That won't be a problem in any of these newer technologies you mentioned? Commented Sep 20, 2017 at 21:16
  • 1
    I have never tried to store that much information locally so I can't say anything about that but I can say that in 5 years a lot changed. I think you should do a small test project and test all the options you have and decide it for yourself Commented Sep 20, 2017 at 21:20
  • Tool recommendation requests are explicitly off-topic here. See #4 in the "some questions are still off-topic" section of stackoverflow.com/help/on-topic Commented Sep 25, 2017 at 22:00

5 Answers 5

10

consider react native as front end library thats need a restful api to connect so you can make backend with php and react native will receive data from it

if you need local database you can use react-native-local-mongodb

or react-native-sqlite-storage

or react-native-sqlite

also if you use redux you can also use redux-persist

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

6 Comments

I won't have internet access most of the time. So the Restful API won't be useful.
I updated my question to state the performance requirements. I already tried realm and despite being praised as one of the fastest db out there for react native, it has already failed my performance requirements by a substantial margin. Before I evaluate each local db one by one, do you know if any of the options you listed will meet the specified performance requirements? I prefer not to explore dead end options.
monogodb is fast but it is no sql database sqllite is sql based but less in performance and ignore redux persist as it work better with small data not large
thanks, maybe you might have insight into my problem here for sqlite storage? stackoverflow.com/questions/46459063/…
|
6

I have not used those other databases that people listed, but I would recommend Realm. Very useful, fast, fully integrated with react-native and very well documented.

https://realm.io

5 Comments

I tried Realm but I'm experiencing performance issues as described in this question here stackoverflow.com/questions/46394870/… . Do you know how to improve query speed in realm? Otherwise, Realm will not be an adequate solution.
@John for the late response. Have you tried in release mode? In debug mode it's really slow, but when you go to release you don't feel any slowness.
All real offerings have a cloud component. Am I mistaken? I am looking for local device storage only
@ManuelHernandez you could do this with realm-js.
Thank you, but I found out that I was able to set up a decent enough CRUD operation with two arrays of objects, filter, map and persisiting on AsyncStorage. The sample is a little lengthy so its a gist gist.github.com/ConnectedReasoning/… if your data needs are simple I'd recommend this.
1

You can use SQLite, it has a native plugin for React Native : https://github.com/andpor/react-native-sqlite-storage

3 Comments

I updated my question to state the performance requirements. I already tried realm and despite being praised as one of the fastest db out there for react native, it has already failed my performance requirements by a substantial margin. Do you know if SQLite will meet my performance requirements? I've read in some blogs that it will not, so don't want to lose time exploring dead options
@John, used properly, SQLite is really darned fast. The only place (other than concurrency) where it lags behind the big databases is that it doesn't have a heavy-duty query optimizer, but that just means it's on you (the user) to build optimized queries.
@DanielMedina thanks, do you know how to solve this problem here? stackoverflow.com/questions/46459063/…
1

As of now, WatermelonDB seems to fulfil both size limit and performance requirements.

Realm is now commercial and tightly coupled to MongoDB and their cloud services (or at least it seems like that from the documentation).

I've also had a quick look at PouchDB, but one of it's react-native integrations stockulus/pouchdb-react-native is based on AsyncStorage (which from my experience is terribly slow), and other one craftzdog/pouchdb-react-native is based on sqlite, but has no activity in last few years.

Comments

0

As per my experience, it totally depends upon the application requirements. If your application is not large scale you can use React Native's default Async Storage, if you are using redux, you can use redux-persist and provide it async storage plugin so it will persist your reducers automatically.

In other case, if you have a large scale application and you are much concerned about the database, you should use WatermelonDB, as it is the best available database for React Native. It also provide synchronising functionality through which you can create an online/offline app with database automatically being synced to the backend. WatermelonDB is also using SQlite on its backend to store data but its more powerful and useful

Comments

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.