Now that I can query couch...

16 views
Skip to first unread message

Shree Mulay

unread,
May 12, 2011, 2:53:22 PM5/12/11
to Clojure Clutch
What can I do with the results?

I've been able to follow through on the examples @
http://www.ibm.com/developerworks/java/library/j-couchdb-clojure/index.html
and able to get answers from Couch. Question is, how do I take those
responses and reuse them in my code elsewhere? Is there any good
examples out there explaining this?

Thanks,

shree

ps. Suppose, I'm a user that logs into a web based "social network"
and I wanted to retrieve my messages from the social network. This
social network, incidentally has all user's messages stored as
documents in couchdb. so, the query is run against the db, and a
response is sent back. Question is, how do we convert that response
into a map or some sorta' sequencable data set that clojure can use?

Shree Mulay

unread,
May 12, 2011, 7:35:48 PM5/12/11
to Clojure Clutch
Um,

Let me rephrase:

When we request a view, the response is weird. How can I actually use this in my clojure code in an app?

http://www.ibm.com/developerworks/java/library/j-couchdb-clojure/index.html#listing20


{:total_rows 6,
 :rows [{:id "d6993381eb5ede34fded2f018b9f10b0",
         :key "Psycho",
         :value 105}
        {:id "84bbfce1b0e4cf6c9aa2f4196909f39d",
         :key "Psycho",
         :value 109}
        ...]}

Any thoughts would be appreciated!

Thanks,

shree

Chas Emerick

unread,
May 12, 2011, 11:46:11 PM5/12/11
to clojure...@googlegroups.com
I'm not sure what you're asking.  The contents of the view's :rows sequence is entirely within your control, so how you structure it is application-specific…

- Chas

Shree Mulay

unread,
May 12, 2011, 11:47:50 PM5/12/11
to clojure...@googlegroups.com
I'm not the most proficient clojure user. I'm quite the newb, actually. How would I be able to manipulate the returned data/get access to it?

Thanks,

shree
--
Shree Mulay's eSignature
-----------------------------
http://twitter.com/#!/ShreeMulay
http://facebook.com/shreemulay
-----------------------------
IN GOD WE TRUST : A CALL TO FAITH : vimeo.com/8142114
-----------------------------
Google Group for The Universal Scripture Viewer:  http://snipurl.com/universalscriptureviewergooglegroup
-----------------------------

Chas Emerick

unread,
May 12, 2011, 11:54:45 PM5/12/11
to clojure...@googlegroups.com
Using their example, you could get all of the values from the view using:

(->> (clutch/get-view …)
  :rows
  (map :value))

which would return [105, 109, …].  That would be a regular Clojure seq, which you could manipulate in all the way that seqs can be manipulated.  You wouldn't be able to update the view's contents directly -- they are generated on demand by CouchDB.  However, if you updated the documents that are represented in the view results, and re-retrieved the view, it would reflect those changes.

- Chas

Shree Mulay

unread,
May 14, 2011, 3:54:00 PM5/14/11
to Clojure Clutch
Dear Chas, et al.,

It appears I need to brush up on sequences(and destructuring) to
figure this out. I appreciate everyone's thoughts.

Thanks,

shree
Reply all
Reply to author
Forward
0 new messages