领域,检查架构版本 [英] realm, check schema version

查看:37
本文介绍了领域,检查架构版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Realm for Android,我想知道如何获取当前的架构版本.在他们的迁移示例中,版本增加然后保存,但我需要在进行任何升级之前检查版本.谢谢.

I'm using Realm for Android, I'm wondering how to get the current schema version. In their Migration example, the version is incremented then saved, but I need to check the version before doing any upgrade. Thanks.

推荐答案

您可以使用以下代码在迁移前获取 Realm 的当前架构版本.

You can use the below code to get the current schema version of Realm before migration.

Realm.init(context);
RealmConfiguration realmConfig = new RealmConfiguration.Builder().build();
DynamicRealm realm = DynamicRealm.getInstance(realmConfig);
long version = dynRealm.getVersion();//this will return the existing schema version
dynRealm.close();

这篇关于领域,检查架构版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆