views:

1035

answers:

1

I´m in touch with CouchDB and the idea of mapping its results to Scala objects, as well as find some natural way to iteract with it, came immediatly.

But I see that Dynamic languages such as Ruby and Javascript do things very well with the json/document-centric/shchema-free aproach of CouchDB.

Any good aproach to do things with Couch in static languages?

+12  A: 

I understand that CouchDB works purely with JSON objects. Since JSON is untyped, it's tempting to believe that it's more naturally suited for dynamic languages. However, XML is generally untyped too, and Scala has very good library support for creating and manipulating XML. For an exploration of Scala's XML features, see: http://www.ibm.com/developerworks/library/x-scalaxml/

Likewise with JSON. With the proper library support, dealing with JSON can feel natural even in static languages. For one approach to dealing with JSON data in Scala, see this article: http://technically.us/code/x/weaving-tweed-with-scala-and-json/

With object databases in general, sometimes it's convenient to define a "model" (using, for example, a class in the language) and use JSON or XML or some other untyped document language to be a serialized representation of the class. Proper library support can then translate between the serialized form (like JSON) and the in-memory data structures, with static typing and all the goodies that come with it. For one example of this approach, see Lift's Record which has added conversions to and from JSON: http://groups.google.com/group/liftweb/msg/63bb390a820d11ba

Jorge Ortiz
Thanks Ortiz! It would be nice to do with JSON what we can with XML in Scala, right?
paulosuzart
Yeah. I think n8han's library (linked above) is a fantastic start, but a lot more can be done for better JSON library support in Scala.
Jorge Ortiz