Is it possible to use two different database for offline web application - postgresql

I have a web application which currently uses postgres database. But I would like to make my application work in offline too. I found that CouchDB/PouchDB supports offline for web applications. But it says I have to use CouchDB in my existing backend instead of postgres.
I would like to know is it possible to implement CouchDB in web app without changing the existing postgres database?
Do I need to change the postgres database to couchDB to implement this feature?

It is possible to do this - at least in theory. And I have certainly not done any work in this area yet so I cannot advise you on how to implement it. But PouchDb does support LevelUp as a backend to the PouchDb Server (I am not sure if this also applies to the PouchDb client).
This means that you could use PouchDb for your offline web application and sync data to the PouchDb Server, but use the LevelUp capability to use PostGres SQL as the PouchDb Server storage service.
There is a good article by Nolan Lawson entitled "PouchDb levels up" that describes this capability here.

Related

how can I work my online java web application to work in offline?

I want to add the feature of database synchronization to my project. It should be like this:
When the internet connection is available the application should transact with the online database server.
When the internet connection is not available it should keep track of the transactions and should update the local DB to online DB server when connection is available it should synchronize.
How can I do this?
Before that we are using Multi Tenant concept in our web application. Single online DB can access all clients using multiple schema.
I want to know how can my web application work in offline mode. If I use HTML5 application cache concept means the HTML and CSS file will load from cookies. How can I get the database value from database when application goes offline.
What is a good way to make my application work online and offline with database?
Most modern browsers have databases or persistence facilities similar to a database for pretty much exactly this use case.
You may end up having to dive pretty deep into javascript to get it to work though. (Especially when the online DB comes back online and you have to go back through all the offline data and send it up (post) to the server end)

Plone usefulness for Backend Development

We have a python based server that uses mongodb database. Our server programs uses RabbitMQ to exchange request/reply packets with many Android apps and perform actions accordingly. In addition to this, now we also need to create a web portal for the admin staff to let them manipulate the database, upload/download files, view data/statistics and trigger actions for android clients. So, the database is going to be common for the portal and the existing server programs.
For the web portal development, I got a recommendation for using Plone. We are comfortable in using traditional Node.js. Could anybody guide me on the use of Plone within this context. Is plone able to communicate with mongodb and existing server side programs?
Plone is a CMS designed around managing web based content and is tightly integrated for storage of its data in the ZODB, a NoSQL database. If data is very custom and isn't all about webpages and website nagivation etc, or if you have a need for the data to live in a different kind of DB then Plone probably isn't the right tool for you. This isn't to say it can't be made to do these these things but you would have to learn a lot about it's internals to make it do these things.

How to have complete offline functionality in a web app with PostgreSQL database?

I would like to give a web app with a PostgreSQL database 100% offline functionality. In an ideal case the database should be completely replicated in the browser per user, and synchronized when online. So that the same code can be used to talk to both the offline and online database. I know this is possible with PouchDB and CouchDB, but have not found a solution that works with PostgreSQL. Is this at all possible?
Short answer: I don't know of anything like this that currently exists.
However, in theory, this could be made to work...(long answer:)
Write a PostgreSQL backend for levelup (one exists for MySQL: https://github.com/kesla/mysqldown)
Wire up pouch-server to read/write from your PostgreSQL db using pouchdb's existing leveldb adapter (which in turn will have to be configured to use your postgres backend). Congrats, you can now sync data using PouchDB!
Whether an approach like this is practical in reality for your application is a different question you'll have to answer.
You may be wondering, for example, "will I be able to sync an existing complex schema with multiple tables to the client with this approach?" The answer is probably not - the mysqldown implementation of leveldown uses a single MySQL table with three fields: id, key, and value (source), and I imagine any general-purpose PostgreSQL adapter would be similar (nothing says you can't do a special-purpose adapter just for your app though!).
On the other hand, if you were to implement a couchdb-compatible API (or a subset- you may not need attachments, for example) over your existing database schema, there's nothing stopping you from using PouchDB on the client to talk directly to that as if it were an actual CouchDB - just pop in the URL and call replicate()! Implementing the replication protocol might be a fair bit of work, since you'd need to track revisions and so on somewhere - but again, technically not impossible!
There are also implementations of levelup's backend storage that are designed for browsers. See level.js, which could be another way to sync between a server-side Postgres levelup backend and the browser.
TL;DR: There's tons of work being done around Javascript databases right now. Is syncing with Postgres impossible? probably not. Would it be a lot of work? Definitely. Worth it? Who knows, but it would be cool.
Without installing PostgreSQL on the client? No. Obviously you can cache data for offline use, but an entire RDBMS+procedural languages in Javscript, no.

Tutorial to Connect iPhone app with MySQL database? (Interface Objective-C with mysql)

I am looking for a tutorial on how to make an iPhone app that fetches data from and writes data to a MySQL database. I've seen some other threads saying that I should make an abstraction layer so as not to connect directly to the database from my app, but I'm not sure of how to actually go about doing this. Does anyone know of any tutorials that involve creating an abstraction layer for a MySQL database or connecting a MySQL database to an iPhone app?
To clarify, I am looking for a secure method that wouldn't allow people to sniff out my MySQL host, username and password. It seems like the libraries that connect directly to MySQL from the iPhone all have this problem, but please correct me if I'm wrong.
This is a really good tutorial that covers how to communicate with MySQL from an iPhone app using PHP:
http://www.raywenderlich.com/2941/how-to-write-a-simple-phpmysql-web-service-for-an-ios-app
I know only one library, which makes possible connection from iPhone to MySQL. This is port of official MySQL C libraries created by Karl Kraft.
Author published also small portion of samples, which describes how to use this library.
UPDATE (Karl Kraft's broken link)
Instead of link above, I used an archived copy.
not up to date, but this tutorial helped me a lot:
http://codewithchris.com/iphone-app-connect-to-mysql-database/#connectiphonetomysql
Here http://blog.iosplace.com/?p=30 is a snippet that uses the original mysql client lib, and here http://www.karlkraft.com/index.php/2012/01/ is a link to a 3rd-party connector.
Here is a nice tutorial on how to connect to a database using web service layer.
From a practical perspective you could connect directly to a database from an iphone because that is a client server transaction. The problem is that you would need to expose your database server an issue that many would find very disturbing, because you would expose your server which hold your most valuable resource "your data". Of course you can implement and could be a good solution for rather small projects. But you would need to implement the layer which it would be used to connect on the iOS app, adding more complex to the matter.
Using a web service is more reliable even from the iOS developer, because there is a very extensive api for using web service, which offer great functionality (asynchronous transactions, threads management,JSON Mapping, XML Mapping) to name a few.
Use the library OHMySQL. It copes with MySQL through MySQL C API.

How to access remote MySql database from iPhone App

I am trying to access a remote MySql database from my iPhone application. I googled, but I can't find anything that works. Can any one suggest a clear way to do this?
Since the iOS SDK does not contain any API's that can access a MySQL database, you have two options:
Implement whatever is necessary in order to talk to a MySQL database engine.
Talk to an application sitting in between your iOS application and your MySQL database.
Of the two, nbr. 2 is by far the easiest, and the normal way to do that is to set up a web service somewhere that you can talk to.
You will have to implement web service methods for whatever kinds of operations you need to perform on your MySQL database.
Exactly how to talk to that web service, and exactly how to talk to the MySQL server from your web service, those are separate questions.