server-side couchdb access using classic ASP

Once in a while some new technology pops up that makes me want to experiment a little. CouchDB is one of these technologies. If you haven’t heard of CouchDB before, Matt Aimonetti has a neat presentation on it over on slideshare.

Although I’m trying to find out what programming language to dive into next (python and c# being my main candidates), I’m still most proficient in classic ASP.

Now the interesting thing about CouchDB is that it’s API’s are in javascript. Querying is done by javascript and it returns JSON (Javascript Object Notation) objects as results. The people at couchDB have included a client-side javascript library to interface to the database client-side, so directly from a browser. Now that’s nice and all, In theary this allows you to build a web-app totally client-side, but I’d really like my data access code on the server, where it’s not visible to everyone.

Classic asp ofcourse has javascript support built-in, so ironically, classic asp is a language that lends itself quite well by default to talk to CouchDB server-side. So one of the oldest web-languages is (unintentionally) one of the most fit to talk to one of the latest database technologies.

Anyway, it seems I’m not the first one that figured this out, and I found an extended version of the javascript library included with CouchDB, by Nathan Smith. This is already something that’s directly useable from ASP. You can include the script in your server-side ASP page, and talk to a couchDB database.

I needed to take this one step further though, I wanted this library encapsulated in a .WSC file. If you’ve read some of my other posts, you know I use wsc’s to create objects in ASP, so the spaghetti-code argument a lot of people have against classic ASP is no longer valid.
The thing with WSCs is that, unlike includes, you can conditionally use them. An include in an ASP file has a lot of overhead, because it is, by default, always included. The server includes the file, and then the ASP interpreter goes ahead and processed the page. In a WSC you can keep your code separate from your ASP pages and conditionally (I.E. in an if…then statement) load them. Anyway, let’s not get sidetracked here.

It was kind of hard to encapsulate the code the way I wanted to, ideally  I would have the WSC and use it like so:

var couchdb;
var newDb = couchdb.createDb('testdb');

Instead, I had to have a function in the WSC that creates a new object and internally instantiates and returns the couchDBserver object. The code now looks like this:

var couchdb;
var server = new Object();
server = couchdb.server("");

Also, I haven’t figured out yet how to use the library using VBscript instead of javascript, but the proof of concept is there. The code is hosted on launchpad, so it can be looked at and improved upon.

Please note that the code needs a couchDB database set up somewhere. I have done this by installing it on my linux laptop and running it from there. The ASP code runs on my Windows workstation. The installation of CouchDB on Windows seems to be quite cumbersome still, so a separate machine (this could also be a virtual machine) is propably the simplest way to go at this point in time.

If you have an improvement or something nice you’ve done with this library, please share in the comments, or better yet, on launchpad. I’m curious to see if I’m the only living classic ASP developer left tinkering with this stuff :)


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: