简体   繁体   中英

Cannot find my .realm file to see in realm browser and cannot see Result

Pardon me for asking such a silly question. I am trying to use Realm DB for my app and i am stuck at how to see my database on realm browser. Also i tried to see the path and find it in my files. I didnt find any realm file. how do i go about it? Also i am interested to see my result set and the queries, which presently i am having trouble with. here is the code.. I am open to suggestions and better implementation practices. Also is it better to make a separate schema file and a separate file where I initialise my schema.. ? Cannot see my filter results.

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>
   );
  }
}

If you are running on Android, you have to copy realm file from your application's internal storage and paste it somewhere on your computer and then browse file using realm browser.

You can find realm file at data/data/$application_package_name/files path.

Update: This answers your question. https://stackoverflow.com/a/28465803/1282812

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM