NoSQL DBs and AppStudio

From NSB App Studio
Jump to navigation Jump to search

A Little Bit of Background

Before I (Ricardo Carraretto) get into the real thing, I'd like to first share a bit of history:

If you have been into WebApp creation, you probably realized that it is not just the application itself, you'll need to also have other stuff on your backend to be able to make the application meaningful. Considering I'm an old-fashioned programmer, I initially chose the "comfort zone" and had my server based on a LAMP model (Linux-Apache-MySQL-PHP, while other might prefer WAMP. You can figure out what W stands for).

The MySQL part was easy and creating all the tables and relationships was kind of fun and reminded me of the joy of normalizing data and creating all those relationships, indexes, views and so on. Then I had to think about the hard part: how could I interact with the server DB from my app? Easy: PHP as the frontend and I'm done. A friend of mine recommended a look on APIgility [1] and it realy helped with the API-like heavy-lifting and it was quite easy to implement a RESTful HAL+JSON API on top of it, talking to my MySQL database.

Next step, why not cache some records on the WebApp WebSQL (or SQLite if you prefer). By doing this, the app will look faster and it will also work offline. I started coding the caching mechanism and after a long couple months I realized that I was spending much more time on programming the "support" for my application than the application itself.

Now enter CouchDB/PouchDB. If these names sound weird, you definitely should Google about them.

CouchDB

CouchDB [2] is a initiative from Apache Software Foundation that supports a "Database for the Web" (as the creators refer to CouchDB). It is a NoSQL, document-store database, that has several neat features that can really help speeding up your WebApp development:

1) It is fast enough for most applications; 2) The documents are stored as JSON objects; 3) It provides authentication for your users; 4) It is only accessible through HTTP, which makes it perfect for Ajax calls within AppStudio; 5) It can synchronize seamlessly to other CouchDB instances; 6) It's free, and there are PouchDB-like Cloud providers, where you can host your DB for free!


PouchDB

PouchDB [3] is a JavaScript implementation of CouchDB. It is very easy to add to your AppStudio project (just as easy as adding any JavaScript library) and it provides a rich API and lots of plugins to ease the task of accessing your data.


So what is in for me?

Give it a try. It is easier to start with PouchDB as it can all be done within the boundaries of AppStudio. You don't need to worry about your browser, as PouchDB will use the best persistence method available (IndexedDB first, then WebSQL, then LocalStorage).

Then install CouchDB on your computer, play a little bit with it and when you're ready for production, you can sign up for an IrisCouch [4] or Cloudant [5] account and depending on the volume of data you use, it will run for free.

Happy coding!