Realm.exists()静态方法是否正常工作?

时间:2020-02-05 19:33:03

标签: react-native realm schema config

我不确定是否可以将其视为错误,但是,如API documentation of the static method exists()中所述,此方法需要 config ,并应指出是否存在领域,并且我注意到了一个奇怪的问题行为。我正在使用一个名为 UsersDatabase.realm 的自定义领域,并且该领域已经存在(通过检查文件系统来确保)。

在我的App启动时,我检查该领域是否已经存在。

这是我创建领域的方式:

let realm = new Realm({
  path: 'UserDatabase.realm',
  schema: [
    {
      name: 'user_details',
      properties: {
        user_id: {type: 'int', default: 0},
        user_name: 'string',
        user_contact: 'string',
        user_address: 'string',
      },
    },
  ],
});

重新启动应用程序后,我将运行此功能:

console.log(
  'realm exists? ' +
    Realm.exists({
      path: 'UserDatabase.realm',
      schema: [
        {
          name: 'user_details',
          properties: {
            user_id: {type: 'int', default: 0},
            user_name: 'string',
            user_contact: 'string',
            user_address: 'string',
          },
        },
      ],
    }),
);

在控制台上,我读到:

领域存在吗?是

直到这里一切正常,它可以按预期运行。但是,如果我运行相同的函数,请更改属性的名称,例如从user_contact更改为usercontact

console.log(
  'realm exists? ' +
    Realm.exists({
      path: 'UserDatabase.realm',
      schema: [
        {
          name: 'user_details',
          properties: {
            user_id: {type: 'int', default: 0},
            user_name: 'string',
            usercontact: 'string',
            user_address: 'string',
          },
        },
      ],
    }),
);

在控制台上我仍然得到:

领域存在吗?是

因此,我假设Realm.exists(...)仅检查领域是否存在于给定的路径上,并且不检查作为参数提供的那个与在文件系统上找到的那个之间的模式等效性。它是正确的?

如果是,那么为什么该方法需要 config 而不仅仅是 path

注意:对我们来说,检查架构之间的健全性至关重要,因为我们正在将应用程序更新为新版本,而在旧版本中,我们使用了不同的架构。我们将维护以前版本的领域的数据,并向新的领域架构进行一些迁移。

0 个答案:

没有答案