rn-app更新的realm数据迁移

realm 数据迁移

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
static db = new Realm({
path: 'db.realm',
schema: tableList, // 数据表配置
// 版本号:如果本地表格修改了,可以通过这个参数进行迭代更新
schemaVersion: 2,
migration: (oldRealm, newRealm) => {
if (oldRealm.schemaVersion < 2) { // 数据表迁移内容,与新版本兼容
Util.devLog('migration realm')
let oldObj = oldRealm.objects('recentGame')
let newObj = newRealm.objects('recentGame')
for (var i = 0; i < oldObj.length; i++) {
newObj[i].id = i;
}
}
}
});

realm 本地储存操作

使用教程

api
api