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 :
- expo-sqlite: missing JSON_EXTRACT https://expo.canny.io/feature-requests/p/expo-sqlite-ship-newer-sqlite3-version-on-android
- react-native-sqlite-storage:
TypeError: e is not a function. (In 'e(r)', 'e' is undefined)
- react-native-sqlite-2: (does not load with expo)
{"name":"TypeError","message":"null is not an object (evaluating 'RNSqlite2.exec')"
- react-native-quick-sqlite: (does not load with expo)
Error: Base quick-sqlite module not found.
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.