MrDMAdev
MrDMAdev

Reputation: 182

Realm with react-native

I've been sifting through the docs for Realm and I can't figure out two things:

  1. What is the default path that Realm stores the DB upon creation via the app using Realm?

  2. What tools are available to pre-populate a DB? An editor that's JSON friendly?

  3. Where in my project structure would a pre-populated DB reside?

Thanks.

Upvotes: 3

Views: 938

Answers (2)

MrDMAdev
MrDMAdev

Reputation: 182

For anyone that stumbled across the original question about #2, I found a tool that addresses this: Realm Browser.

https://itunes.apple.com/us/app/realm-browser/id1007457278?mt=12

Upvotes: 2

Ari
Ari

Reputation: 1447

  1. The default path is in the documents directory on ios and in the data directory on android with the filename default.realm. This path can be read/set by accessing Realm.defaultPath.
  2. There isn't currently a great solution for importing JSON. The browser supports csv import if you want to convert to that first. You could also write a simple ReactNative app to create a db and you could copy that data out. There is a node.js binding under development but it is not yet released although it is in the repo if you want to try to get that working.
  3. For iOS you can store the db in the resources directory (you specify this in your xcodeproj) - on android you would bundle it by putting it in the assets directory. The realm-test-app project bundles realm files if you want an example. To access the bundled files directly you need to open them readOnly. Alternatively you can call Realm.copyBundledRealmFiles() to copy all realm files bundled with the app to the default data directory at which point you can open them normally.

Upvotes: 1

Related Questions