请原谅我问了这么愚蠢的问题。我正在尝试将 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>
);
}
}