Skip to content


as3couchdb

The library is available on github at bustardcelly/as3couchdb. You can read more detailed information on the wiki. The document API is available online at http://custardbelly.com/as3couchdb/docs.

The following is a cross-post of a section from the Announcing as3couchdb Library post:

When i set out on creating the as3couchdb library, i knew i wanted to follow a similar approach to Data Access Objects. I wanted to make all my requests through the object i was working with and have an intermediate layer that communicate with the service and updated the object accordingly. To achieve this, i went about creating a base model class that contains a model entity. The model entity is really only involved in parsing custom metadata and resolving the information to properties held on the base model. Extending the base model are the two core models of CouchDB that you interact with: the Database and the Document.

So the Database and Document models can be though of as the Business Objects and expose methods that related to CRUD operations. Even though CouchDB has a REST API, i chose using simple CRUD method signitures on the models as they seem easier to read and understand. From these methods, the models interact with a service mediator (similar to Data Access Object), which knows how to communicate with the service proxy and has action handlers that know how to modify the model once a successful result is received. To put it in code terms:

I wanted to have the ease of creating and storing a document as such

var contact:ContactDocument = new ContactDocument();
contact.firstName = "Todd";
contact.lastName = "Anderson";
contact.addEventListener(CouchActionType.CREATE, handleContactCreate);
contact.create();

And the ease to simply read in for modification as such:

var contact:ContactDocument = new ContactDocument();
contact.addEventListener(CoachActionType.READ, handleContactRead);
contact.read( $uid );

In order to make this all work and auto-wire the models with a service mediator, custom annotations were needed. This is where the model entity mentioned earlier comes into play. When extending the core models (as ContactDocument does in the previous examples) you add custom metadata that relates to the CouchDB instance you intend to work with and the fully qualified classnames of the target service mediator and request object.

Now the request object is a different story and was brought into the picture due to the lack of HTTP method types available for the web version of Flash Player. As such, there are a couple different request object types available in as3couchdb: straight-up devil-may-care requests using URLRequest (mainly for AIR or you will get RTEs), one that uses External Interface, and one that uses as3httpclientlib. The as3httpclientlib allows you to make PUT and DELETE requests using a Socket and is the best way to interact with a RESTful service when limited to the Flash web player (imho).

Some useful links:
CouchDB – http://couchdb.apache.org/
CouchDB: The Definitive Guide – http://books.couchdb.org/relax/
CouchDB: Wiki – http://wiki.apache.org/couchdb/FrontPage
MongoDB, CouchDB and MySQL Compare Grid – http://www.mongodb.org/display/DOCS/MongoDB,+CouchDB,+MySQL+Compare+Grid
as3httpclientlib – http://github.com/gabriel/as3httpclient

More information about the custom metadata, and the inner workings of as3couchdb can be found on the wiki for the project in github.


0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.



Some HTML is OK

or, reply to this post via trackback.