Y_J
Y_J

Reputation: 81

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 didn't 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>
   );
  }
}

Upvotes: 0

Views: 593

Answers (1)

Kalpesh Patel
Kalpesh Patel

Reputation: 1678

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

Upvotes: 1

Related Questions