1

The author mentions that his premium plugin rxdb-premium/plugins/storage-sqlite is not working on older version of SQLite on Android, if we get the error mentionned below (in the next code block). So, expo uses SQLite version 3.32.2 instead of 3.38.0 to use JSON_EXTRACT.

Anyone found a way to make expo work with his plugin without using pouchdb-adapter on Android with any react-native SQLite database? I know that expo-sqlite works only on iOS, like he said it would.

The error below, and his page mentionning the error in the "requirements" section

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

I will like to use his storage wrapper for expo getSQLiteBasicsExpoSQLite with a sqlite database that works. I tried :

I get my storage like so:

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;
}

these are some libs from my 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",

I also disabled pretty much all other features and only render a splash screen to wait for the db to mount and resolve, so no replications, so I have no data to insert in the database, only waiting it to mount.

I would like to find a way to make sqlite work with rxdb and expo.

EDIT: I made my own module expo-sqlite-storage but it cannot be used inside ExpoGO until the expo team upgrade their module expo-sqlite. This module is the same as the original, except it uses requery/sqlite-android database instead of android.database.sqlite to a more updated version of sqlite.

1 Answer 1

0

Have you looked here? https://github.com/pubkey/rxdb/tree/master/examples/react-native

I managed to get the example working with Expo after updating the RN version.

1
  • This is half a clarification question (which should be in a comment instead of an answer post) and half a link-only answer (which is usually deleted on StackOverflow, because the answer itself is supposed to be right here). Linking and summarizing how the solution works (in contrast advertising * what* it achieves) would be OK. But you seem to just confirm that it works - not how. Please edit to make more obvious how this is an answer according to How to Answer.
    – Yunnosch
    Commented Aug 5, 2023 at 7:17

Not the answer you're looking for? Browse other questions tagged or ask your own question.