craftzdog / pouchdb-adapter-react-native-sqlite

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

Intermittent errors when reading form a view for the first time #26

Closed martin-ecatch closed 4 weeks ago

martin-ecatch commented 1 month ago

First of all - this adapter is amazing! Thanks for all the hard work!

The problem I'm facing after upgrading to V4: when reading from a view for the first time, I get an error: Error: [op-sqlite] SQL statement error on opsqlite_execute: no such table: local-store

This happens in only ~5% of the cases, and only on the first read (when PouchDB is building the index for the view). My suspicion is a race condition - the new database for the view (xxxx-mrview-xxxxx) is not ready (the migrations haven't been applied yet).

Any help would be appreciated!

martin-ecatch commented 1 month ago

I found the issue. There's an extra callback(null) on line 11 in index.ts. This is called without waiting for the database setup. The callback gets called in the correct place in core.ts line 124. I'll prepare a PR (which basically just removing line 11 from index.ts).

craftzdog commented 4 weeks ago

Thanks for the PRs!