Find path for Realm file with Realm React Native to use with Realm Browser

寵の児 提交于 2019-11-29 14:20:42

问题


On iOS, it is possible to inspect the contents of a Realm database by opening the corresponding file with the Realm Browser. The path to that file can be printed by using the following line of code (as noted here):

print(Realm.Configuration.defaultConfiguration.path)

Is it possible to do the same when using the React Native version of Realm?


回答1:


Just found the answer myself by digging through the docs:

console.log('create db:', db.path)



回答2:


Just in case you can't get the above to work. Here is how I did it:

1) import the file in which you define the schema and create a new realm into a component that will mount when you refresh the simulator.

import realm from './path_to_file_where_realm created'

2) console.log(realm.path) in the componentWillMount() lifecycle method & enable remote debugging to see the output.

3) open up realm browser and click open realm file. Command Shift G on mac will let you paste in the path from the console.log

click on the realm file to open it with the realm browser.

Also for those not familiar with the realm browser, it can be found here. It just lets you see & edit data in your realm with a graphical interface.




回答3:


In my case i used,

const Realm = require('realm');
console.log('REALM PATH', Realm.defaultPath);


来源:https://stackoverflow.com/questions/36517440/find-path-for-realm-file-with-realm-react-native-to-use-with-realm-browser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!