Document Information

Last modified:
2008/09/05 09:59 by wpbasti

CouchDB

CouchDB Support Code

This contribution provides client-side access to a CoucbDB server using a REST api. For this purpose, part of this contribution is also a more generic neutral rest-library.

For more information about CouchDB see: http://incubator.apache.org/couchdb/

CouchDB Quick Start

This is a quick overview to get you started with CouchDB the data base and CouchDB the contribution.

The documentation is still a bit sparse, but it should work pretty intuitively. The most difficult part, I think, is setting up a couchDB server and making the webserver that is hosting your qooxdoo project proxy a specific path to the couchDB server. This is required because of the security limitations of modern browsers concerning cross-domain requests.

Below, i’ll show:

1) how to use the contribution in your project
2) a simple example code
3) how to setup the couchdb server in Ubuntu.

Using the contribution

In your qooxdoo project’s makefile, put:

      APPLICATION_INCLUDES = contrib://CouchDB/trunk

Everytime your make your project, it will check for updates and download them from svn if available. You need subversion installed offcourse.

A simple example

   couch.Default.configure('mydatabase', 'path/to/couchdb',
'username', 'password');
   var myDoc = new couch.Document('mydocument');
 
   myDoc.setKey('type', 'recipe');
   myDoc.setKey('ingredients', ['milk','egg','flower' ]);
   myDoc.setKey('name', 'pancakes');
 
   myDoc.save();
   myDoc.once('available', function(){
     alert('document is now saved and available on the server!');
   });

Setting it up on Ubuntu (and likely all other debian derivatives):

  sudo apt-get install automake autoconf libtool subversion-tools
help2man build-essential erlang libicu38 libicu-dev libmozjs-dev
  mkdir couchdb
  cd couchdb
   svn co http://svn.apache.org/repos/asf/incubator/couchdb/trunk couchdb
  ./bootstrap
  ./configure
  make && sudo make install
  sudo adduser  --home /usr/local/var/lib/couchdb  couchdb
  sudo cp /usr/local/etc/init.d/couchdb /etc/init.d/couchdb

Now you can launch the couchdb server with:

  sudo /etc/init.d/couchdb start

It is not started automatically when you boot-up though, but since it’s not stable software yet, that might be a Good Thing ™ Also note that it runs on its own user for security purposes. (it could be simpler .. )

Now try to see if it works:

  http://localhost:5984/_utils/

This should show you futon .. the built-in web-administration. (Nice, huh?) Remember couchDB uses rest, so GET queries can be tested directly in the database.

If you try:

   http://localhost:5984/

You get the current status of server:

{"couchdb":"Welcome","version":"0.7.3a661200"}

It’s all http queries (GET|PUT|POST|DELETE) and JSON. However, your webserver you likely run on localhost:80 isn’t allowed to access localhost:5984 because of security restrictions with XMLRemoteRequest thingie. So, you need to setup a proxy. Assuming you are running Apache2:

  sudo aptitude install apache2 apache2-mod-rewrite-html
  sudo a2enmod rewrite proxy proxy_http

Make sure you are allowed to rewrite urls in your .htaccess files A typical entry in /etc/apache2/sites-available that does that would be:

<VirtualHost *>
	ServerAdmin webmaster@localhost
	Alias /mysite /path/to/site
	<Directory /path/to/site>
	   Options Indexes FollowSymLinks MultiViews
	   AllowOverride All
	</Directory>
</VirtualHost>

It’s the AllowOverride that does the magic .. Now in your site’s document root, do this:

  cd /path/to/site
  mkdir couch
  cd couch
  nano .htaccess

In that .htaccess file you should put:

RewriteEngine   on
RewriteRule     ([^\/]*)\/_view\/([^\/]*)\/(.*) http://localhost:5984/$1/_view/$2/$3 [p]
RewriteRule     ([^\/]*)\/([^\/]*)\/(.*) http://localhost:5984/$1/$2\%2F$3 [p]
RewriteRule     (.*) http://localhost:5984/$1 [p]

Press control+o to save and then control-x to exit the nano-text-editor. Now, let’s reload apache:

  sudo /etc/init.d/apache2 reload

Then try to see if the rewriting works. Open the following url:

  http://localhost/mysite/couch

So, the path to couch is now mysite/couch. You’re done ;-)

Information

Last modified:
2008/09/05 09:59 by wpbasti

Account

Not logged in

 
 

Job Offers

To further improve qooxdoo we are seeking javascript developers. Read more...

Rich Ajax Platform (RAP)

RAP uses qooxdoo, Java and the Eclipse development model to build rich web applications. Read more...

qooxdoo Web Toolkit (QWT)

Similar to GWT this framework allows to create impressive qooxdoo applications just using Java. Read more...

Pustefix

Pustefix is a MVC-based web application framework using Java and XML/XSLT. Read more...

 
SourceForge.net Logo

Bad Behavior has blocked 0 potential spam attempts in the last 7 days.