如何解决RxDB Premium与Expo React Native SQLite兼容问题?
持有RxDB Premium授权,使用rxdb-premium/plugins/storage-sqlite插件时,在Expo React Native的Android设备上无法正常工作。原因是Expo内置的SQLite版本为3.32.2,而该插件需要SQLite 3.38.0及以上版本才能支持JSON_EXTRACT函数,触发的错误信息如下:
WARN Possible Unhandled Promise Rejection (id: 0): Array [ Object { "error": [Error: no such function: JSON_EXTRACT (code 1 SQLITE_ERROR): , while compiling: CREATE INDEX IF NOT EXISTS "rxdb_deleted_lastWriteTime_idx" ON "_rxdb_internal-0"(JSON_EXTRACT(data, '$.deleted'), JSON_EXTRACT(data, '$.lastWriteTime'), deleted);], }, ]
尝试过的不兼容SQLite库(均无法满足需求)
expo-sqlite:缺失JSON_EXTRACT函数react-native-sqlite-storage:触发TypeError: e is not a function错误react-native-sqlite-2:无法在Expo中加载,触发null is not an object (evaluating 'RNSqlite2.exec')错误react-native-quick-sqlite:无法在Expo中加载,触发Error: Base quick-sqlite module not found错误
注:曾自行开发expo-sqlite-storage模块,但暂无法在ExpoGO中使用。
最终解决方案
使用v14及以上版本的RxDB,搭配50及以上版本的Expo SDK即可开箱即用,不同SDK版本的导入方式如下:
- Expo SDK 50:
import * as ExpoSqliteStorage from 'expo-sqlite'; - Expo SDK 51:
import * as ExpoSqliteStorageLegacy from 'expo-sqlite/legacy';(该方式将在SDK 52移除) - Expo SDK 52:
import * as ExpoSqliteStorage from 'expo-sqlite';
内容的提问来源于stack exchange,提问作者jwallet
相关产品推荐
相关产品推荐

