我正在尝试从领域db查询,但未定义。
DogService.js
import Realm from 'realm';
import {databaseOptions} from '../models'
export const DogService = {
findAll: async () => {
Realm.open(databaseOptions).then(
realm => {
const result = realm.objects('Dog')
console.log(result) // <=got result
return result;
});
},
save: () => {
Realm.open(databaseOptions).then(
realm => {
realm.write(() => {
realm.create('Dog', {name: 'Alex'})
});
});
}
}
App.js
async componentDidMount() {
let realm = await DogService.findAll();
console.log(realm); // <= undefined
}