'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 1:[1]

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.

Solution 2:[2]

Another possibility (which may or may not work with your use case, depending on how your data is structured):

You can move some of your data (just what needs to sync to the browser) to CouchDB, but give Postgres access to it through the Foreign Data Wrappers feature in Postgres, so that you don't need to convert your entire app to putting everything in CouchDB, and you don't lose the benefits of a relational database.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Community
Solution 2 iconoclast