DEV Community

Hacking PouchDB to Use It on React Native

Takuya Matsuyama on April 04, 2019

UPDATE(2021/02/12) Created PouchDB@7 for React Native Takuya Matsuyama ・ Feb 12 '21 ...
Collapse
 
badbod99 profile image
badbod99

Looks good. I wonder if it's possible to polyfill the buffer logic rather than forking pouchdb to sort the attachment issue. Otherwise, might be worth putting together a PR for a new option to the PouchDB repo for forcing base64 when buffers are not supported/available.

Collapse
 
craftzdog profile image
Takuya Matsuyama

I've tried rn-nodeify to polyfill Buffer but it didn't solve the issue.

Collapse
 
garfieldnate profile image
Nathan Glenn

Thanks so much for putting this together! I tried out the demo and it worked great. I was surprised to see that you have a simple "hello, world!" text encoded as base64. Why did you do that? Do all attachments have to be base64-encoded with your method?

Collapse
 
craftzdog profile image
Takuya Matsuyama

That's because I wanted to demonstrate storing attachments works fine on RN apps. "Hello, world" text is useful for that.
Right. All attachments must be encoded in base64 to let PouchDB avoid calling readAsBinaryString.

Collapse
 
juliogarma profile image
Julio Márquez • Edited

Hi takuya,

I apply your changes but still I cannot see the base64 image. I can see the _attachment field but with a weird format (maybe blob)

  • I also set the encoding to plain/text
  • In couchdb server I can see the image

But when the synchronization tries to download the image back to the device its in a wrong format.

I can see the attachment has this form: 77+977+977+....9AAAA....

Could you please advise how did you solve this?

Thanks a lot in advance

Collapse
 
duytq94 profile image
Duy Tran • Edited

I have the same problem, image attachment has a weird format with 77+9UE5HDQoaCgAAAAAAAAAA...
I think it still a blob type since the structure of this object is like this:
Alt text of image

Collapse
 
rdewolff profile image
Rom

Thanks, wanted to mention the same. You're right, except there are some issues with attachments (see github.com/stockulus/pouchdb-react...), but they are working on it.

Collapse
 
greenais profile image
Alexander

Sorry to say, but it doesn't and they dont, unfortunately. Project seems to be abandoned, look at open issues.
Sure you can still use it if you don't need replication (what?), but asyncstorage would be easier.

Thread Thread
 
rdewolff profile image
Rom

Replication does work, but not attachment.

Collapse
 
vittaljk profile image
vittal

I am getting this error
TypeError: WebSqlPouchCore.call is not a function

Collapse
 
productivix profile image
productivix

hi, how did you solve this issue please ?

Collapse
 
sl0tr profile image
Mohaimin Islam

Where are these SQLite DBs located on the phone? Does it exist in the app installation directory and will get removed upon app un-installation? If so, is there any DB that I can store outside the scope of the app installation so that it doesn't get removed after un-installation?

Asking because building a very offline first accessible app where the user might not be aware enough to know that uninstalling the app might lose all offline data.

Collapse
 
snehalagrawal profile image
SnehalAgrawal
Collapse
 
cilvet profile image
Iñigo Cilveti

Hi! would it be possible to use this in order to have a preloaded database (including indexes) in a react-native app? thanks!

Collapse
 
snehalagrawal profile image
SnehalAgrawal

Yes you can, You just need to do some addition things
Example to Load Pre Populated SQLite Database in React Native

Collapse
 
duytq94 profile image
Duy Tran

Thank you so much!

Collapse
 
productivix profile image
productivix

the example does not work : see issue

Collapse
 
hayate profile image
Andrea Belvedere

こんにちは Takuyaさん,

Thank you for your great work!
In the section "polyfill functions that PouchDB needs" why is "events" required to be installed?