有任何方法可以让RxDB使用SQLite数据库在Expo上为React Native工作(我拥有RxDB Premium,SQLite插件不工作)

dgenwo3n  于 2023-06-06  发布在  SQLite
关注(0)|答案(1)|浏览(394)

作者提到他的高级插件rxdb-premium/plugins/storage-sqlite不能在Android上的旧版本SQLite上工作,如果我们得到下面提到的错误(在下一个代码块中)。因此,expo使用SQLite版本3.32.2而不是3.38.0来使用JSON_EXTRACT
有没有人找到一种方法,让expo可以使用他的插件,而不需要在Android上使用任何react-native SQLite数据库的pouchdb-adapter?我知道expo-sqlite只能在iOS上工作,就像他说的那样。
下面的错误,his page在“需求”部分提到了这个错误。

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);],
  },
]

我想使用他的存储 Package 器为博览会getSQLiteBasicsExpoSQLite与sqlite数据库的工作。我试过:

*展会信息:缺少JSON_EXTRACT https://expo.canny.io/feature-requests/p/expo-sqlite-ship-newer-sqlite3-version-on-android
*react-native-sqlite-storageTypeError: e is not a function. (In 'e(r)', 'e' is undefined)

  • react-native-sqlite-2:(不带expo装载){"name":"TypeError","message":"null is not an object (evaluating 'RNSqlite2.exec')"
    *react-native-quick-sqlite:(不加载Expo)

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团队升级他们的模块expo-sqlite。此模块与原始模块相同,除了它使用requery/sqlite-android数据库而不是android.database.sqlite到sqlite的更新版本。

wyyhbhjk

wyyhbhjk1#

你找过这里了吗https://github.com/pubkey/rxdb/tree/master/examples/react-native
在更新RN版本后,我设法让这个例子与Expo一起工作。

相关问题