CouchDB example, starting points?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

CouchDB example, starting points?

bestguy
Hi,

Thanks for the nice framework.

I'm a Scala newbie, and attempting to use dispatch.couch.

I couldn't find any examples for binding/extracting Couch responses to pojos using the dispatch.Doc and dispatch.Id classes.

By looking through the codeusing the liftweb json parser, I got the following to work for me:

import dispatch._
import dispatch.couch._
import net.liftweb.json.DefaultFormats
import net.liftweb.json.JsonParser._

val http = new Http
val db = Db(Couch(), "example")

val text = http(db / "02a678af5d7408bf812fecc5d1d693ae" as_str)

implicit val formats = new DefaultFormats
val json = parse(text)
var pojo = json.extract[MyPojo] // MyPojo is a simple case class
println(pojo)


This works okay, but wondering how I could do the equivalent using Doc and Id without using the liftweb parser?


Thanks!

Reply | Threaded
Open this post in threaded view
|

Re: CouchDB example, starting points?

n8han
Administrator
Hi, there are some examples of getting data out documents using dispatch.couch in the tests:
http://databinder.net/sxr/dispatch-couch/0.6.4/test/CouchSpec.scala.html

Also, this small document server that I use for the Dispatch web site uses that interface:
http://technically.us/git?p=sling.git;a=blob;f=src/main/scala/sling/Press.scala;h=a1643080ebf8f3bb31bf6f88be63c615b5431d91;hb=HEAD

But, I'm not sure that dispatch.couch would be suitable for a larger project without more development. Other people have developed interfaces to couch using Dispatch that are further along, one using dispatch-json:
http://github.com/debasishg/scouchdb

And another using dispatch-lift-json:
http://github.com/frank06/surf

Nathan