Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to pre-package Realm database (default.Realm) through React-Native (JS)

I have played around with Realm, got it to work with React-Native - Got the data inserted from JSON file and was able to filter/read it too.

Now the real question, how can i pre-package the data with my react-native app. I have seen some questions, where it is mentioned on how to do it with Native (IOS) and (Android)

I wanted to check if there is a direct way to do it with React-Native, may be a bridge someone created?

Thanks!

like image 432
Abhay Avatar asked Apr 17 '16 22:04

Abhay


1 Answers

Ideally you would be able to just use the path of your bundled realm file when opening the Realm. Unfortunately this will not work until support for read-only realms is added. I created an issue to track this: https://github.com/realm/realm-js/issues/392

Until read-only realms are supported, you can copy the bundled realm file into your Documents directory at app launch in your AppDelegate and then use that path to access the bundled Realm. Relative paths are supported so if you copy your file to <Documents>/bundled.realm you can open this file by just passing in the file name, ie new Realm({path: 'bundled.realm'})

like image 182
Ari Avatar answered Sep 17 '22 23:09

Ari