postgresqlindexeddbpouchdbofflineapps

Syncing PouchDB offline to PostgreSQL


I am trying to make my web application work on offline mode by using pouchDB. but the backend database server i used is PostgreSQL (NoSQL). I couldn't find a way to Sync my PouchDB data to postgreSQL when my app came back to online. Can anyone please give me an idea how to do it


Solution

  • Short answer: You can't. It's impossible. Give up. You need CouchDB.

    Long answer: You have two options:

    1. you can implement a custom replicator for PouchDB (it is just a PouchDB plugin -- that can get complicated, but not necessarily --, see the default Pouch-Couch replicator source code); or
    2. you can set up a backend service that acts as a proxy between PouchDB and Postgres, that will basically require you to understand and implement the CouchDB replication protocol, i.e., you'll need a server with a bunch of HTTP endpoints that return exactly what the PouchDB replicator expects.

    See also this answer from another question.