查询领域数据库异步时未定义

时间:2019-08-24 03:53:14

标签: react-native realm

我正在尝试从领域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
}

0 个答案:

没有答案