Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto sync data between couch and mysql

I need to develop offline app for the web application which is already developed with apache, mysql and php. I just found that we can develop offline app with couch and pouch db.

But the think is I need to auto sync data from mysql to couch db (and couch to mysql also ). From my understanding that I can write php code to read data from mysql and put the data to couch db ( and also with couchdb to mysql ). But I am not sure that how we can keep couch db and mysql data as updated. ( I mean auto sync the data when the changes are happen at the one end ).

can anyone suggest me the tool or anything to find out the way to auto sync data ?

like image 321
Pushpa Avatar asked May 07 '18 07:05

Pushpa


1 Answers

There is not a generic solution for this kind of synchronization. You should write your own code for that.

You should write a mapping mechanism that converts your relational data model into documents and vice versa.

From MySQL you'll require a change detection mechanism to determine the data that should be transferred to CouchDB after each synchronization cycle (ej. use timestamps as checkpoints), convert the data into json docs and then save/merge it with the CouchDB content.

From CouchDB, you can listen for document changes using the _changes endpoint and for every change transfer it to the MySQL by transforming them into DML operations.

All of this depends on your use case and could be difficult to writte a generic integration mechanism.

like image 115
Juanjo Rodriguez Avatar answered Nov 13 '22 18:11

Juanjo Rodriguez