4

I'm new to mobile development and I need to build a local storage for an app, this is where I've heard of Realm. Could you give me more information about how exactly Realm stores data in the application?

Is it a file or ...? And how do you manage app updates in order to not lose the data already in the user's phone?

Thank you

Florin Pop
  • 5,105
  • 3
  • 25
  • 58

1 Answers1

3

Realm stores data in a proprietary binary format in a .realm file on the devices filesystem. If you are running the iOS simulator its visible and can be opened with the Realm Browser application.

Realm handles updates in two ways. You can use the Realm Object Server. You would make all changes to a central server and realm handles all the syncing for you. If you want to destructively change the db model you would have to clone your server realm an then serve a new one to the new version of your app. Or if you have local database instances on your devices you handle changes to the DB model with migrations.

AdamG
  • 2,570
  • 3
  • 24
  • 35
  • Thank you. So.. let's suppose I have an "initial database" with some dummy data. The user is able to manipulate that data. How do I make sure that when I update my app in App Store/Google Play, the changes the user made to that "initial database" aren't overwritten? – Florin Pop Jun 07 '17 at 06:48
  • Basically, I don't really need to change the db model. I just don't want to overwrite the changes the user made to the db... Let's consider a "facebook like" app, where you have some photos and the user can like and dislike photos. Initially all the photos have their "like" flag set to false, and then the user can change it to true. How do I keep this change when I upgrade the app later with new functionality? – Florin Pop Jun 07 '17 at 06:51
  • I would make your initial db writes, as well as any addition of data required by future updates, via code, as opposed to thinking about shipping out a pre-set DB file with each version. – AdamG Jun 07 '17 at 23:53
  • So basically I need to check always when the app opens that the db data is correct? How should I do that? – Florin Pop Jun 08 '17 at 08:29
  • Its a little hard to say wthout knowing more about your apps design and how you are modeling and storing data. Perhaps you should look at the Realm Object Server which will allow you to maintain a true sync with your clients. You can then have remote tables that store your user data by their id. – AdamG Jun 09 '17 at 22:18