Use PouchDB as embedded database within phonegap app - html

I'm just getting started with PouchDB. I would like to be able to use PouchDB within HTML5 apps for mobile devices created using Phonegap or Cordova. While going through the Getting Started guide on the PouchDB site, it looks like you are supposed to run through a server (or localhost) rather than through the file system. As I am trying to create an app which runs offline, wouldn't a Phonegap app, in essence, be using the file system on the mobile device and not a server/localhost?
I'm sure this is a basic question, so forgive me if this is too obvious, but I haven't found anything clear on this topic through my searches.
Thank you.

PouchDB is able to sync with a remote database running on a server, such as CouchDB, Cloudant, or Couchbase.
However, it's also perfectly OK to run it as a purely local database. When you do:
var db = new PouchDB('foobar');
...then you have a local database called "foobar," using either IndexedDB, WebSQL, LevelDB, SQLite, or whatever the browser/device supports. So ultimately it writes to the local filesystem.
Hope that helps!

Click here!
I reckon this may be a good example for you build a offline apps. In fact, you could use Angular + pouchDB + websql. I am working on some projects which related to that. Look forward to further questions.

Related

How to store data in a client app and download data to a main server (ionic 2/angular 2)?

I'm developing an app in Ionic 2/Angular 2/Cordova and I need to implement this behaviour: storing data in the client app and download data of each client to the main server database, periodically, as soon as the mobile data network on the device is available.
What is the current best practice to do this?
I would think SQLlite database on the app, mySQL database on the server and a web service for the app to call and send data. There is something pre-built to do this? (coding this from scratch seems to me like reinventing the wheel)
EDIT: after some researches I've found something called PouchDB (son of CouchDB) but I'm not sure it is sufficiently used/supported by the community to use it and hope to find help online in case of problems

AngularJs real time app with mysql server

Is it possible to build a realtime app using AngularJs with a mysql database?
I've been reading thousands of tutorials, but they are all focused on express, nodejs, etc.. didn't found any documentation on wheter it's possible or not. I tried to take a look at the socket.io docs, but still didn't found anything relevant to this question.
I didn't tried anything yet because of this. I use a webApp based on AngularJs on a apache server (local).
Where should i start to be able to build a real time app using these tools i have?
Do i really need to use a node/express server?
What are the main consideration i need to do before taking this step?
Is there any documentation i should read?
I need to do this real time because it involves product orders, call center, ticket system, etc.. So everytime there is a new ticket is opened/changed, new order arrives, etc.. I need to make the user aware of this, without the need to refresh the page.
Or if someone could give me a further explanation of this concept and how to get started, it will be great.
You can run angular on top of any backend, although most examples push towards REST. If you want your app to feel like a real time application, using WebSockets is a likely improvement.
WebSockets play nice with Angular, look at https://github.com/wilk/ng-websocket for example. A back-end in Node will work, but many other backend techs will do equally well.
Here is a decent tutorial using MySQL, NodeJS, and Angular: https://codeforgeek.com/2015/03/real-time-app-socket-io/
I recommend that you keep using a webserver like Apache (my personal preference is Nginx). You can proxy API and socket requests to Node, and serve static resources for the app from a folder.
Check out https://httpd.apache.org/docs/2.4/mod/mod_proxy_wstunnel.html if you stay with Apache. Check out http://nginx.org/en/docs/http/websocket.html is you go for nginx.
Without a webserver, you'll have to either:
serve your static resources with Node (polluting your server project with client code), or
work with different ports, risking the app becomes unusable in client environments, or
work with different domains, giving you a CORS head-ache.
Although I don't have much experience with Node, MySQL with Node.js should help you out a bit.
You'll want to move away from Apache if you want to do websocket stuff with Socket.io
Yes, it is possible to create a software with AngularJS in the front end and any other server side language that speaks to MySQL. Few months back I worked on a software with Java Spring Framework in the backend with MySQL database and AngularJS with bootstrap in the front end. You could start by following the MVC pattern, where your views can be served as AngularJS and your Controller can be in any server side code, with MySQL database.

indexedDB in a Chrome App

I'm building a chrome app which requires a persistent and local database, which in this case can be either indexedDB or basic object storage. I have several questions before i begin developing the app:
Is it possible to persist indexedDB data after un-installation of the chrome app and chrome browser?
If the indexedDB file/data persist can i locate and view it?
If I can locate but can't view it, is it possible to change the location of the indexedDB file?
Can I store the indexedDB in a file located on desktop or any other custom location?
If I had these requirements, I see a couple of options that you might pursue
Write a simple database backed by the FileSystem API, and periodically lock the database and back up that file. This would be pretty cool because I don't know of anyone who has implemented a simple FileSystem API backed database, but I could see it being useful for other purposes.
Any edits to the database would be also made to a copy of the database stored on your backup server, and I would write functions that could import snapshots from your backup.
Simply write functions to export from your indexedDB to some format into a backup, and to import from the backup.
All options seem quite time consuming. It would be cool if when you create an indexedDB, you could specify an HTML FileSystem API entry file to back it, and that way you wouldn't have to do 1 or 2.
I agree that it seems like quite an oversight that an indexedDB is quite difficult to back up.
I am writing a basic browser only application. No back end server code at this time. So I also have storage requirements. But I am not doing backup. I am looking at pouchdb as a solution: http://pouchdb.com/
Everything is looking good so far. They also mention that they would work well with Google Apps.
http://pouchdb.com/faq.html#native_support
The nice thing is you could sync your pouchdb data with a server couchdb instance.
http://pouchdb.com/api.html#replication
http://pouchdb.com/api.html#sync
If you want to keep the application local to the browser with no server support you could backup the entire database by using a batch fetch.
http://pouchdb.com/api.html#batch_fetch
I would run the result through gzip before you put it on the filesystem.
I am currently attempting this very same thing. I am using the Chrome Sync File System Api (http://goo.gl/5q8Z9M), but running into some instances where my file (or its contents) is deleted. With this approach I am writing out a JSON object. Hope this helps.

iOS and Mac OSX communicating with MySQL database

I have a client who wants a control panel for the app I am developing them. The control panel is a Mac OSX application that allows the user to submit files (excel docs and such) to my MySQL database. Those files are then checked by the iOS app I have created for them.
I have no idea how to do this. I have the MySQL database all set up, and I have looked everywhere for a solution. Any help is appreciated.
I wouldn't try to connect to your MySQL database directly from your cell phone. It's a bad design for several reasons. Instead build a API on the same server as the MySQL database. It doesn't matter if you do it in java, php, c# or anything else. You might even find some product or open source project that can do this automatically. I've listed some benefits of doing it this way
It makes testing easier. You can write a test framework against your API that doesn't rely on or is using a phone.
It makes development faster. You don't need to emulate or use a phone to develop and test your table design and queries.
It gives you compatibility. When you need to change your database (and you do) you can create new APIs that the new version of the app uses while and old version still out there can continue to use the old API (that you might have to modify to still provide the same functionallity)
It gives you flexibility. If your user base grows and you might need to have replication for reads or sharded databases you build that into the API instead of into the app which is just a better way to do it.
One option would be to use PHP to handle all the database interaction.
Host the scripts on the server and just have the apps call them and get the scripts to return some sort of parseable response (I'd go for JSON).
I have never found a suitable Object-C based connector for MySQL. At this point I would suggest using a C/C++ connector. There's lots of examples of how to configure the connector for both C and C++. The hard part will be all of the data passed from the MySQL code and the Object-C code will that it will have to be in C types.
EDIT: An Example

Desktop programming language to connect to remote MySQL

A customer of mine asked me a better and faster solution to update it's real estate web site as he and his employees don't want to connect to the web site and update one by one the ads as they don't want to loose time waiting the normal latency of the internet.
I firstly solved the issue by building a PHP script that imported an Excel file into the web site's MySQL database and it worked greatly. But the problem were pictures that have still to be uploaded separately. I then wrote a PHP script that uploaded the pictures using ajax and drag&drop so the user could select multiple pictures and upload them at once. And this worked too, but the customer is still not completely satisfied as he says this solution is quite 'patched'.
I then thought about a desktop application - a kind of local database (could be SQLite) - that the user keeps updated locally and only at the end of the day the app connects to the remote server and updates the db and uploads the pictures.
My question is: what EASY desktop high level programming language I could use to do the job? Do you know any RAD (visual IDE) programming language able to connect to a remote mySQL server and upload data via a simple custom GUI?
I tried RealBasic and PureBasic but I did not work it out. I thought about building the app in PHP and then convert it to EXE but I did not tried yet.
Please don't suggest me Java, C or Delphy as I'm looking for something very easy.
Thank you
Have you considered a client side javascript/html app that syncs with the server, since you're already familiar with the platform? If one browser better supports what you want to do (Firefox has some extension perhaps vs Chrome, or whatever), than mandate that to run this app (rather than worrying about being portable across browsers).
All of the browsers can have client side storage now, and you can just do things locally, and finally push them to the server "all at once".
If your client is using a Windows platform, you could use IronPython (.NET), VB.NET, or C#. These all allow you to create windows/forms visually in Visual Studio. If you're not already familiar with the .NET platform I'm not sure how 'easy' this will be, but I think that's going to be true for most other platforms as well.
That being said, it sounds like your existing solution is probably the best idea - perhaps if you can make your solution feel less like a "patch" they will be satisfied.
No reason you can't use Purebasic if that's what you're comfortable with. There are HTTP file upload examples on the PB forums.
I've used Purebasic for years but I'd recommend spending the time to get to know C#/.NET - it's a world of difference and once you learn it stuff like this is pretty easy.