开发者

Simple object retrieval from CouchDB in Scala

I'm Scala/CouchDB newbie with a simple use case. I need to store some Scala case class instances into the CouchDB. The data in the instances are "almost" static (update happens only during my service restart).

All I need is:

  1. Insert the instance to CouchDB
  2. Get the instance from CouchDB

I'm trying to use Scouchdb (https://github开发者_如何学运维.com/debasishg/scouchdb).

  • I can use sjson for object serialization, but I would expect scouchdb to do it on its own.
  • I know about by_id(id) and get(id) method for retrieval, but I'm kinda not able to figure it out - it seems all examples are out of date

Can anyone give me simple example (if such exists) how to achieve my goal?

And last but not least, is there any relation between dispatch-couch and scouchdb?

Thanks


The methods I needed are found on Db class

For inserting:

/** create a doc from an object with auto id generation */
def doc[T <: AnyRef](obj: T)

For retrieval there is:

/** get an entity of type <tt>T</tt> based on its id. Returns a
Tuple3 of (id, ref, T) */
def get[T](id: String)

See https://github.com/debasishg/scouchdb/blob/master/src/main/scala/scouch/db/Database.scala

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜