Skip to content

Adapter feature question / request #41

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

Open
gabrielgrover opened this issue Jan 15, 2025 · 3 comments
Open

Adapter feature question / request #41

gabrielgrover opened this issue Jan 15, 2025 · 3 comments

Comments

@gabrielgrover
Copy link

Hello @craftzdog . My team has benefitted from your work for a long time. We appreciate your contributions to the react native community. I wanted to know if an adapter system with this library is possible? We aren't able to use op-sqlite and would like to stick with expo-sqlite. Happy to do the work myself. I wanted to know if you have a suggestion of where to start or even if this is possible. Thank you!

@ccatalani-modocu
Copy link

We have similar issue: we are using react-native-sqlite-2 + @craftzdog/pouchdb-adapter-websql-core and an update to op-sqlite does break existing installations. Now we are upgrading RN to 0.76.6, but websql is no longer working correctly. Queries for non existing pocuhdb documents do not return (disappearing in a black hole.. :-) ).
Our idea is to adapt pouchdb-adapter-react-native-sqlite latest version to work with react-native-sqlite-2 again: do you think, it's a feasible way?

@craftzdog
Copy link
Owner

sqlite database files are compatible between expo-sqlite, sqlite-2, and op-sqlite since they are just wrappers.
You can specify a path to load the existing database file.

import {
  IOS_LIBRARY_PATH, // Default iOS
  IOS_DOCUMENT_PATH,
  ANDROID_DATABASE_PATH, // Default Android
  ANDROID_FILES_PATH,
  ANDROID_EXTERNAL_FILES_PATH, // Android SD Card
  open,
} from '@op-engineering/op-sqlite';

const db = open({
  name: 'myDb',
  location: Platform.OS === 'ios' ? IOS_LIBRARY_PATH : ANDROID_DATABASE_PATH,
});

Learn more: https://op-engineering.github.io/op-sqlite/docs/configuration#absolute-paths

Currently, there is no way to specify a custom location in this adapter because PouchDB doesn't support specifying adapter options.
Maybe you can tweak the init function to make it possible:

https://github.com/craftzdog/pouchdb-adapter-react-native-sqlite/blob/master/src/index.ts

Another solution would be to move the existing db files to the default location of op-sqlite.

@ccatalani-modocu
Copy link

Many thanks for your reply, it's very helpful. 🙏

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