如何在React Native中使用Sqlite和Expo?

huangapple go评论65阅读模式
英文:

How to use Sqlite with expo in React Native?

问题

"react-native-sqlite-storage" 是否与 Expo 配合使用,还是必须使用 expo-sqlite?我正在尝试创建一个严重依赖数据库的应用程序,但出现了两个错误:

错误 TypeError: 无法将空值转换为对象,js 引擎:hermes

错误 不变性违规:"main" 未注册。这可能是因为:

  • Metro(本地开发服务器)在错误的文件夹中运行。请检查是否正在运行 Metro,停止它,然后在当前项目中重新启动它。
  • 由于错误而导致模块加载失败,并且未调用 "AppRegistry.registerComponent",js 引擎:hermes

此外,关于这个错误似乎在线上有很少的信息,这时我了解到了 expo-sqlite。

英文:

Does 'react-native-sqlite-storage' work with expo or it is compulsory to use expo-sqlite. I am trying to create an app which heavily depends on a database but for some reason 'react-native-sqlite-storage' shows me two error,

ERROR TypeError: Cannot convert null value to object, js engine: hermes

and

ERROR Invariant Violation: "main" has not been registered. This can happen if:

  • Metro (the local dev server) is run from the wrong folder. Check if Metro is running, stop it and restart it in the current project.
  • A module failed to load due to an error and AppRegistry.registerComponent wasn't called., js engine: hermes

Furthermore, there seems to be very little information regarding this error online and that's when I found out about expo-sqlite.

答案1

得分: 1

你可以使用 expo-sqlite(https://docs.expo.dev/versions/latest/sdk/sqlite/)

使用 react-native-sqlite-storage 似乎不是一个好主意:

  1. 你将无法使用 react-native-sqlite-storage,因为它包含了本地代码。
  2. 这个项目似乎已经不再维护。

从技术上讲,你可以通过构建自己的 Expo 客户端或者弹出应用程序来使用这个模块,但如果没有真正必要,你 不应该 这样做。

英文:

You can use expo-sqlite (https://docs.expo.dev/versions/latest/sdk/sqlite/)

Using react-native-sqlite-storage seems to be not an good idea:

  1. You won’t be able to use react-native-sqlite-storage as it contains
    native code
  2. The project seems to be no longer maintained

Technically you can use the module by building your own expo client or eject the app but you should not do that if it isn‘t really necessary.

huangapple
  • 本文由 发表于 2023年7月13日 19:13:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/76678722.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定