作者提到,如果我们收到下面提到的错误(在下一个代码块中),他的高级插件
rxdb-premium/plugins/storage-sqlite
无法在 Android 上的旧版本 SQLite 上运行。因此,expo
使用SQLite版本3.32.2
而不是3.38.0
来使用JSON_EXTRACT
。
有人找到了一种方法,可以让 expo 与他的插件一起使用,而无需在 Android 上使用
pouchdb-adapter
和任何 React-Native SQLite 数据库吗?我知道 expo-sqlite
只适用于 iOS
,就像他说的那样。
下面的错误,以及他的页面在“要求”部分提到了错误
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);],
},
]
我想将他的存储包装器用于世博会
getSQLiteBasicsExpoSQLite
以及可以运行的sqlite数据库。我试过了:
TypeError: e is not a function. (In 'e(r)', 'e' is undefined)
{"name":"TypeError","message":"null is not an object (evaluating 'RNSqlite2.exec')"
Error: Base quick-sqlite module not found.
我的存储空间如下:
import * as exposqlite from 'expo-sqlite';
import sqlite2 from 'react-native-sqlite-2';
import { getRxStorageSQLite, getSQLiteBasicsExpoSQLite } from 'rxdb-premium/plugins/storage-sqlite';
function getStorage(key: 'expo' | 'sqlite2' | 'memory') {
switch(key) {
case 'expo':
return getRxStorageSQLite({
sqliteBasics: getSQLiteBasicsExpoSQLite(exposqlite.openDatabase),
});
case 'sqlite2':
return getRxStorageSQLite({
sqliteBasics: getSQLiteBasicsWebSQL(sqlite2.openDatabase),
});
// and more attempts... on differents storage to make expo work with any sqlite db.
case 'memory':
default:
return getRxStorageMemory();
}
}
function createDatabase() {
const storage = getStorage('expo');
const db = await createRxDatabase<RxCollections>({
eventReduce: true,
multiInstance: false,
name: storage.name,
password: env.DATABASE_PASSWORD,
storage,
ignoreDuplicate: false,
});
await db.addCollections(collections);
console.info('RxDB: Database created.');
return db;
}
这些是我的一些库
package.json
:
"expo": "47.0.8",
"expo-sqlite": "11.1.1",
"react": "18.1.0",
"react-dom": "18.1.0",
"react-native": "0.70.5",
"react-native-sqlite-storage": "6.0.1",
"react-native-sqlite-2": "3.6.2",
"rxdb": "14.1.9",
"rxdb-premium": "14.1.9",
"rxjs": "7.8.0",
我还禁用了几乎所有其他功能,只渲染启动屏幕来等待数据库安装和解析,因此没有复制,所以我没有数据可插入数据库中,只能等待它安装。
我想找到一种方法让 sqlite 与 rxdb 和 expo 一起工作。
编辑:我制作了自己的模块expo-sqlite-storage,但它不能在ExpoGO内部使用,直到世博团队升级他们的模块expo-sqlite。该模块与原始模块相同,只是它使用
requery/sqlite-android
数据库而不是 android.database.sqlite
到更新版本的 sqlite。
编辑 2:现在可以开箱即用。使用 v14 以后的 RxDB。使用较新版本 50 的 Expo SDK
import * as ExpoSqliteStorage from 'expo-sqlite';
import * as ExpoSqliteStorageLegacy from 'expo-sqlite/legacy';
,它将在 SDK 52 中删除到 SDK 52 中的最新存储import * as ExpoSqliteStorageNext from 'expo-sqlite/next';
你看过这里吗? https://github.com/pubkey/rxdb/tree/master/examples/react-native
更新 RN 版本后,我设法让示例与 Expo 一起使用。