Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expo with RxDB Premium SQLite, any way to make it work #4536

Closed
jwallet opened this issue Mar 9, 2023 · 8 comments
Closed

Expo with RxDB Premium SQLite, any way to make it work #4536

jwallet opened this issue Mar 9, 2023 · 8 comments

Comments

@jwallet
Copy link
Contributor

jwallet commented Mar 9, 2023

Hello pubkey

since the source code is hidden and you are probably the only one that can answer a premium related question,

how can I make the getter getSQLiteBasicsExpoSQLite works with any sqlite database on expo for react-native on android?

I do not want to use the pouchdb-adapter for sqlite and I tried to setup the SQLite Premium plugin with pretty much every sqlite database without success. your react-native example is running with a database in-memory which is only good for testing. your rxdb-premium sqllite says it works on react-native, I do hope it works on expo in any way.

 switch (storageKey) {
    case 'expo':
      return getRxStorageSQLite({
        sqliteBasics: getSQLiteBasicsExpoSQLite(exposqlite.openDatabase),
        log: console.log.bind(console),
      });
    case 'sqlite2':
      return getRxStorageSQLite({
        sqliteBasics: getSQLiteBasicsWebSQL(sqlite2.openDatabase),
        log: console.log.bind(console),
      });
    case 'sqlitestorage': {
      sqlitestorage.enablePromise(true);
      return getRxStorageSQLite({
        sqliteBasics: getSQLiteBasicsWebSQL(sqlitestorage.openDatabase),
        log: console.log.bind(console),
      });
    }
    case 'quicksqlite':
      return getRxStorageSQLite({
        sqliteBasics: getSQLiteBasicsQuickSQLite(quicksqlite.open),
        log: console.log.bind(console),
      });
    default:
      throw new Error(`RxDB: Crashing... Storage key "${storageKey}" is not supported.`);
  }

you can see the stackoverflow post here

@jwallet jwallet changed the title Expo with RxDBPremium SQLite, any way to make it work Expo with RxDB Premium SQLite, any way to make it work Mar 9, 2023
@pubkey
Copy link
Owner

pubkey commented Mar 9, 2023

From the docs

expo-sqlite cannot be used on android (but it works on iOS) because it uses an outdated SQLite version

So you can use expo-sqlite in iOS, but not on android.
Last week there where some problems fixed with getSQLiteBasicsWebSQL() that can work for you with react-native-sqlite-2.

Notice that there is a rxdb-premium channel in discord, just that you know.

@jwallet
Copy link
Contributor Author

jwallet commented Mar 10, 2023

Thanks pubkey,

Yes, I've seen the documentation page, and I'm on rxdb and rxdb-premium 14.1.9. But, we did hope during the POC, that there was a way to make it work on both android and iOS without ditching expo. Looks like this guy in the issue you linked had more success than me. I still end up with an error with craftzdog/react-native-sqlite-2#22 like mentioned in the stack overflow post

{"name":"TypeError","message":"null is not an object (evaluating 'RNSqlite2.exec')"

some say in that issue that is just incompatible with expo.

it's kind of a let down if the Premium SQLite plugin doesn't even work on android and expo, considering how big expo is in the community. If there is no proper way to set it up with the latest sdk 48, I guess we will try to make it work on rxdb-classic using expo-sqlite with memory storage, will see.

@pubkey
Copy link
Owner

pubkey commented Mar 10, 2023

Can you enable the logging, this might gave a clue on what is wrong.

const storage = getRxStorageSQLite({
  sqliteBasics: getSQLiteBasicsWebSQL(SQLite.openDatabase),
  // pass log function
  log: console.log.bind(console)
});

it's kind of a let down if the Premium SQLite plugin doesn't even work on android and expo, considering how big expo is in the community.

Yes expo is big. But they work on a version of SQLite that is about 3 years old and they do not want to update it. This is their fault and there is not much that I can do about that. Also the rxdb docs contain that information. The correct place to complain about that, is here

@jwallet
Copy link
Contributor Author

jwallet commented Mar 10, 2023

Ok, so that's what I get when I log it using:

import {
  getRxStorageSQLite,
  getSQLiteBasicsWebSQL,
} from 'rxdb-premium/plugins/storage-sqlite';
import sqlite2 from 'react-native-sqlite-2';

// ...

return getRxStorageSQLite({
  sqliteBasics: getSQLiteBasicsWebSQL(sqlite2.openDatabase),
  log: console.log.bind(console),
});

logs:

 LOG  ## RxStorage SQLite log: open(0) sqlite_42a37798-6e4c-44b0-a0a1-2590a0431755_1678135011_1678460000420
 LOG  ## RxStorage SQLite log: open(0) DONE
 LOG  ## RxStorage SQLite log: run(1) {"query":"BEGIN;","params":[]}
# some logs outside of rxdb
 LOG  ## RxStorage SQLite log: run(1593) {"query":"BEGIN;","params":[]}
 LOG  ## RxStorage SQLite log: run(1593) ERROR
 LOG  open transaction error (will retry):
 LOG  {"name":"TypeError","message":"null is not an object (evaluating 'RNSqlite2.exec')","stack":"exec@http://192.168.2.12:19000/index.bundle?platform=android&dev=true&hot=false:265791:18\nhttp://192.168.2.12:19000/index.bundle?platform=android&dev=true&hot=false:264884:13\ntryCallTwo@http://192.168.2.12:19000/index.bundle?platform=android&dev=true&hot=false:26518:9\ndoResolve@http://192.168.2.12:19000/index.bundle?platform=android&dev=true&hot=false:26650:25\nPromise@http://192.168.2.12:19000/index.bundle?platform=android&dev=true&hot=false:26537:14\ny@http://192.168.2.12:19000/index.bundle?platform=android&dev=true&hot=false:264883:23\nhttp://192.168.2.12:19000/index.bundle?platform=android&dev=true&hot=false:264849:18\ngeneratorResume@[native code]\nasyncGeneratorStep@http://192.168.2.12:19000/index.bundle?platform=android&dev=true&hot=false:21753:26\n_next@http://192.168.2.12:19000/index.bundle?platform=android&dev=true&hot=false:21772:29\nhttp://192.168.2.12:19000/index.bundle?platform=android&dev=true&hot=false:21777:14\ntryCallTwo@http://192.168.2.12:19000/index.bundle?platform=android&dev=true&hot=false:26518:9\ndoResolve@http://192.168.2.12:19000/index.bundle?platform=android&dev=true&hot=false:26650:25\nPromise@http://192.168.2.12:19000/index.bundle?platform=android&dev=true&hot=false:26537:14\nhttp://192.168.2.12:19000/index.bundle?platform=android&dev=true&hot=false:21769:25\nrun@http://192.168.2.12:19000/index.bundle?platform=android&dev=true&hot=false:264852:29\nhttp://192.168.2.12:19000/index.bundle?platform=android&dev=true&hot=false:263988:59\nhttp://192.168.2.12:19000/index.bundle?platform=android&dev=true&hot=false:264147:22\ngeneratorResume@[native code]\nasyncGeneratorStep@http://192.168.2.12:19000/index.bundle?platform=android&dev=true&hot=false:21753:26\n_next@http://192.168.2.12:19000/index.bundle?platform=android&dev=true&hot=false:21772:29\ntryCallOne@http://192.168.2.12:19000/index.bundle?platform=android&dev=true&hot=false:26510:16\nhttp://192.168.2.12:19000/index.bundle?platform=android&dev=true&hot=false:26591:27\nhttp://192.168.2.12:19000/index.bundle?platform=android&dev=true&hot=false:27535:26\n_callTimer@http://192.168.2.12:19000/index.bundle?platform=android&dev=true&hot=false:27450:17\n_callReactNativeMicrotasksPass@http://192.168.2.12:19000/index.bundle?platform=android&dev=true&hot=false:27483:17\ncallReactNativeMicrotasks@http://192.168.2.12:19000/index.bundle?platform=android&dev=true&hot=false:27647:44\n__callReactNativeMicrotasks@http://192.168.2.12:19000/index.bundle?platform=android&dev=true&hot=false:20872:46\nhttp://192.168.2.12:19000/index.bundle?platform=android&dev=true&hot=false:20672:45\n__guard@http://192.168.2.12:19000/index.bundle?platform=android&dev=true&hot=false:20852:15\nflushedQueue@http://192.168.2.12:19000/index.bundle?platform=android&dev=true&hot=false:20671:21\nflushedQueue@[native code]\ncallFunctionReturnFlushedQueue@[native code]"}
# it then repeats indefinitely the last 4 logs

@kilbot
Copy link
Contributor

kilbot commented Mar 11, 2023

Hi @jwallet, I am also looking for a good DB option to work with expo. I was actually thinking about creating my own Native Module, I think Expo have made some improvements to the API recently which makes this easier 😬

If we created our own module we could choose a SQLite library that best works with RxDB, or perhaps another DB? Would you be interested in development something together?

@pubkey
Copy link
Owner

pubkey commented Mar 11, 2023

@jwallet from your logs it looks like you are able to create the database connection but running the queries fails.
Can you try using plain SQLite without rxdb and check if there the querying works for you?

@jwallet
Copy link
Contributor Author

jwallet commented Mar 12, 2023

@pubkey I tried it in a new env and my expo-sqlite (updated the android database to support JSON_EXTRACT) is working just fine using my npm package, but when I tried it in my project it failed on me, a different log than the one I got from sqlite2 but really similar . So I guess both should work just fine. (react-native-sqlite-2 should work with expo)

I will check my expo configs. The stack is just so big, but I do know it fails even if in App I just open the simplest sqlite database setup in a hook. So probably not caused by the React code itself. Anyway, close it or keep it open, I will come back later here to leave what is causing the issue , if it can help someone else.

@jwallet
Copy link
Contributor Author

jwallet commented Mar 13, 2023

So I found out the issue comes from using expo go instead of building the native apps locally still using expo: npx exgo run:android|ios.

It did work after, but I faced a new issue after the initial sync. #4552 (same issue using react-native-sqlite-2)

related to craftzdog/react-native-sqlite-2#22

@jwallet jwallet closed this as completed Mar 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants