Realm initial local database for app


#1

Hello,

Recently I started learning more about React Native, and I’m building a mobile app. I need to have a local database and this is where I found Realm (not sure yet if it’s the right choice for what I need).

My scenario is as follows:

  • it will be a mobile app which will show certain data. Let’s call it a list of items, where each item has an id, a text, and a “liked” flag (which is a bool value).
  • the application needs to run offline, so I need to load initially all the data to the user.
  • the user can see the list of items and can manually “like” or “unlike” the certain items, which needs to be stored on his phone.

Is this a good place to work with Realm?
Also, how exactly does Realm work on the app update? (When for example I add new features to the app and I want to make an update in the App Store and Google Play) Will the “local” Realm database be overwritten when the user upgrades?

Thank you for your time!


#2

I just did something similar. RN app, local realm DB. App updates only update app code, they do not overwrite your app’s files directory. So if your app runs the first time, creates a realm data file and puts data into it, then later when the app package is updated with a new version (from google play, app stores, etc) only the app code will be overwritten. Your files will still be there.

I took that one step farther, have a pre-populated realm data file that contains data, which I package with the app. Then, on first run, I copy that from the (read-only) app package into the files directory, and open that file with Realm.

In terms of “is realm a good choice for storing local data?” I think yes. I’m mainly an iOS dev, this is my first RN project, and Realm seemed to be the easiest choice in terms of stability, features, and ease of programming.


#3

Dear William: I am new to Realm and read your post where you stated: “I took that one step farther, have a pre-populated realm data file that contains data, which I package with the app. Then, on first run, I copy that from the (read-only) app package into the files directory, and open that file with Realm.” Would you be so kind as to reveal to me how you did that? I am on Swift 4 and would like to try something like that.

Best docT