craftzdog / pouchdb-adapter-react-native-sqlite

PouchDB adapter using ReactNative SQLite as its backing store
https://github.com/craftzdog/pouchdb-react-native
MIT License
131 stars 25 forks source link

CDB replication + local query is broken #9

Closed greenais closed 6 years ago

greenais commented 6 years ago

I step in your pouchdb adapter in hope to find working solution for bundle of pouchdb on RN + couchdb backend. But it seems that sqlite is broken in the same manner as asyncstorage is, details are here Both - mapreduce and find plugins show exactly same behaviour: after changed docs replication from CDB query starts to show only last updated on server doc, nevertheless all other docs remain untouched in local PDB. My first question: is there any chance that this bug will be resolved in a some visible future?

PDBRN seems unmantained (at least since August), but the only unique thing there is asyncstorage adapter, the rest could be combined of recent pouchdb-core + plugins.

But your adapter depends on PDBRN, so my second question: is there any way to use sqlite adapter in counjunction with pure PDB, without need of PDBRN?

craftzdog commented 6 years ago

is there any chance that this bug will be resolved in a some visible future?

No. It is nothing to do with the bug as it is just an adapter. Use older version.

is there any way to use sqlite adapter in counjunction with pure PDB, without need of PDBRN?

I'm not sure because it's not tested with pure PouchDB

greenais commented 6 years ago

Use older version.

What do you mean - older version of what? PDBRN? It behaves same way

it's not tested with pure PouchDB

It's pity, because now your adapter is depended on broken lib. Your choice, sure

badbod99 commented 5 years ago

@greenais @craftzdog - This adaptor does work with PouchDB directly, i.e. without PDBRN. PDBRN is just a custom build of PouchDB as per https://pouchdb.com/custom.html. The only thing it includes extra is the AsyncStorage adaptor. If you're using SQLite storage, you don't need that. I'm running the SQLite adapter as a local js file to use the 7.0.0 dependencies.

This is my custom build:

PouchDB bits, in packages.json

"pouchdb-adapter-http": "^7.0.0",
 "pouchdb-adapter-websql-core": "^7.0.0",
 "pouchdb-core": "^7.0.0",
 "pouchdb-find": "^7.0.0",
 "pouchdb-mapreduce": "^7.0.0",
 "pouchdb-replication": "^7.0.0",

Dependencies and polyfills, in packages.json

"atob": "2.1.1",
"blob-polyfill": "3.0.20180112",
"btoa": "1.2.1",
"buffer": "5.2.0",
"events": "3.0.0",
"expo": "^31.0.2",
"left-pad": "1.3.0",

Init code for PouchDB.

import PouchDB from 'pouchdb-core';
import HttpPouch from 'pouchdb-adapter-http';
import replication from 'pouchdb-replication';
import find from 'pouchdb-find';
import { SQLite } from 'expo';

import SQLiteAdapterFactory from '../adapters/SQLiteAdapter';
const SQLiteAdapter = SQLiteAdapterFactory(SQLite);

PouchDB
  .plugin(HttpPouch)
  .plugin(SQLiteAdapter)
  .plugin(replication)
  .plugin(find);
badbod99 commented 5 years ago

@craftzdog - Would you accept a PR to update the documentation and include the custom build of PouchDB (as an example build) in this repo?

greenais commented 5 years ago

@badbod99 Thank you for your suggestoins. So you don't experience any of mentioned above issues with broken find/mapreduce outputs after changed docs replication in your expo setup, right? If I don't use expo (just vanilla RN) - is there way to use SQLiteAdapterFactory then? This import looks quite new for me: import SQLiteAdapterFactory from '../adapters/SQLiteAdapter'; Where it comes from?

badbod99 commented 5 years ago

Not yet tested find or map reduce fully, but since it's on the latest PouchDB with WebSQL doing the SQL generation, I don't expect any issues.

The SQLLiteAdapter file is just the .js file for the adapter taken from this project. Moved it locally as this project currently references 6.4.1 and we want 7.0.0 where (I suspect) many of the issues are resolved.

Without expo you'll need another SQLite implementation such as https://github.com/craftzdog/react-native-sqlite-2

craftzdog commented 5 years ago

Thanks for the suggestion, @badbod99.

Made websql-core-7.0.0 branch for this issue. Released pouchdb-adapter-react-native-sqlite@2.0.0 with beta tag on npm so you can try it. If it worked as expected, I would drop the beta.

badbod99 commented 5 years ago

@craftzdog - Seems that replication is broken with this setup. It works fine with remote debugger attached (i.e. running through web worker with Expo), but not without. I'm going to try and debug it.

craftzdog commented 5 years ago

I guess PouchDB uses APIs that JSC doesn't support because it is not a web browser.

badbod99 commented 5 years ago

Managed to sort it. Had to manually add atob and btoa implementions to global. Not yet tested attachments, but otherwise all working. I'll create a repo with the custom PouchDB build, you could then reference that in your docs rather than pouchdb-react-native.

craftzdog commented 5 years ago

Great to hear that. I will give a shot on my production app, too. Yep, let me know when you created it!

greenais commented 5 years ago

@badbod99 did you managed to create a repo with the custom PouchDB build as you planned? I'd ready to test it against issues I mentioned in initial issue - they are still actual for PDBRN, unfortunately..

badbod99 commented 5 years ago

I've got an example up, it's basic but working. Still planning to setup a repo to replace pdbrn properly, but still testing all features. Example project here https://github.com/badbod99/pouchdb-expo-example

greenais commented 5 years ago

Thank you for an update. Please let me know here or via PM when you set up repo - I'm ready to collaborate in testing from vanilla RN side - I have existing CDB + PDBRN project with almost comprehensive PDB functionality involved, but attachments