How to use/package a Realm file in React Native ?
See original GitHub issueI’ve got a realm file “cleverbean.realm” that I want to reference in React Native. My first thought was I could just place the file (“cleverbean.realm”) into its own directory in the React Native project, and then reference that when instantiating the realm.
I copied a realm file into a path off root. ie
./data/cleverbean.realm
I then tried the following to instantiate :
realm = new Realm({
path: './data/cleverbean.realm',
schema: [CleverbeanSchema]
});
That didnt work and threw this error thinking I was trying to resolve via a non project path.
How should I go about ensuring that a realm will be pre-installed on iOS and Android, in the context of a React Native app ? Also what is the correct way to reference those local Realms, when instantiating in the app (per the example code snippet above) ?
Issue Analytics
- State:
- Created 7 years ago
- Comments:14
Top Results From Across the Web
Bundle a Realm File - React Native SDK - MongoDB
Open up the android folder generated by React Native in Android Studio. · In the Project tree, navigate to app > src >...
Read more >How to use/package a Realm file in React Native? - YouTube
How to import Realm file in React Native project.
Read more >Where does realm React-Native store data on mobile apps?
Realm stores data in a proprietary binary format in a .realm file on the devices filesystem. If you are running the iOS simulator...
Read more >How to find realm file — React Native | by Gokulanath A S
How to find realm file — React Native. console.log ("Simulator path of realm file", realm.defaultPath);.
Read more >Top 11 Local Databases for React Native App Development
It makes use of an SDF data file. In case of React Native, there are multiple databases, some of which are – Realm,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks ajonno for your detail explanation. Not sure if we are on the same topic… But actually, I was finding a way to put my pre-populated DB data file into my app, and finally I found a solution!
I post my solution, as I believe people may find this thread when they want to do the same thing - include populated DB data file into app.
However, as I only need a solution for iOS, my solution would cover iOS only. For Android, I think it can be done in similar way.
Put your realm DB file into your XCode project.
Be reminded to add it under Copy Bundle Resource otherwise the file will not be copied to you app when build. You can find it under Build Phases
Define realm DB file path when you declare realm object (This is the most tricky thing… I spent a night to find out solution, because I am newbie of iOS and react-native) The key point is that You need to give the full path of the realm DB file that you put in XCode project. To get the full path, I use react-native-fs to achieve this. With RNFS.MainBundlePath, you can have your app’s base path, and your realm DB file should be there. Another tricky thing is that, you must declare your realm as readOnly: true (Maybe it is not a must if you include some more files to your XCode project, but I didn’t try it)
Hope above solution can help people that encountered same problem.
@vladbars Will this copy the realm file every time we open the app?