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
Syncing PouchDB offline to PostgreSQL
Asked Answered
Short answer: You can't. It's impossible. Give up. You need CouchDB.
Long answer: You have two options:
- 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
- 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.
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.
© 2022 - 2024 — McMap. All rights reserved.