找不到我的.realm文件在领域浏览器中看到并且看不到Result

时间:2017-03-24 06:54:24

标签: javascript react-native realm realm-browser

请原谅我提出这么愚蠢的问题。我正在尝试使用Realm DB作为我的应用程序,我坚持如何在领域浏览器上查看我的数据库。此外,我试图看到路径,并在我的文件中找到它。我没找到任何领域文件。我该怎么办呢? 此外,我有兴趣看到我的结果集和查询,目前我遇到了麻烦。这是代码..我对建议和更好的实施实践持开放态度。还有一个单独的模式文件和一个单独的文件,我初始化我的模式更好吗? 看不到我的过滤结果。

const testScema = {
  name: 'profile',
  properties: {
    name: 'string',
    age: 'int',
    sport: 'string',
  }
};

let realmObj = new realm({schema: [testScema]});

export default class test extends Component {
  constructor(props){
    super(props);
    this.state = {
      name: '',
      sport: '',
      age: '',
    }
  }

  insert(){
    var age = parseInt(this.state.age);
    realmObj.write(() => {
      let myProf = realmObj.create('profile',{
        name: this.state.name,
        age: age,
        sport: this.state.sport,
      });
    });
    let allProfiles = realmObj.objects('profile');
    let filterRes = allProfiles.filtered('name BEGINSWITH "h"');
    this.refs.name.setNativeProps({text: ''});
    this.refs.age.setNativeProps({text: ''});
    this.refs.sport.setNativeProps({text: ''});
    console.log("filter result", filterRes);
    console.log("items in db", realmObj.objects('profile').length);
  }

  delete(){
    let allProfiles = realmObj.objects('profile');
    realmObj.write(() => {
    realmObj.delete(allProfiles);
    });
  }

  render() {
   return (
     <View>
      <Text>For Realm testing</Text>
      <View style={{flexDirection: 'row'}}>
        <Text style={{flex: 1}}>Enter Name: </Text>
        <TextInput ref="name" onChangeText={(name) => this.setState({name})} style={{flex: 1}}/>
      </View>
      <View style={{flexDirection: 'row'}}>
        <Text style={{flex: 1}}>Enter Age: </Text>
        <TextInput ref="age" keyboardType="numeric" onChangeText={(age) => this.setState({age})} style={{flex: 1}}/>
      </View>
      <View style={{flexDirection: 'row'}}>
        <Text style={{flex: 1}}>Enter Favourite Sport: </Text>
        <TextInput ref="sport" onChangeText={(sport) => this.setState({sport})} style={{flex: 1}}/>
      </View>
      <View style={{flexDirection: 'row', justifyContent: 'space-around'}}>
        <Button style={{flex: 1}} title="INSERT" onPress={() => this.insert()}/>
        <Button style={{flex: 1}} title="DELETE" onPress={() => this.delete()}/>
      </View>
      <ListView
        dataSource={ds.cloneWithRows(realmObj.objects('profile'))}
        renderRow={(data) => <Text>{data.defaultPath}</Text>}/>
     </View>
   );
  }
}

1 个答案:

答案 0 :(得分:1)

如果您在Android上运行,则必须从应用程序的内部存储中复制realm文件并将其粘贴到计算机上的某个位置,然后使用域浏览器浏览文件。

您可以在data/data/$application_package_name/files路径找到领域文件。

更新:这回答了你的问题。 https://stackoverflow.com/a/28465803/1282812