You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Paola Lorusso <lo...@yahoo.it> on 2008/10/05 22:47:53 UTC
create views, ruby instead of javascript
Hi ,
I' am trying to use couchdb with ruby. I am using in particular 'couch_object' to interface ruby with couchdb.
I would ask how I can create views in ruby instead of javascript to query couchdb.
In particular I am interested to faster this query following below that queries a blog db, where I have posted comments, posts, and authors.
results1 = Array.new
for post in posts
id = post["id"]
doc = db.get(id).to_document
if doc["type"] == 'post' and doc["title"][0..1]== /xr/ then results1 = doc end
end
I have read samewhere that I can optimize the performance using views. May I do that following this example?
I have seen same exemples on this URL http://theexciter.com/articles/couchdb-views-in-ruby-instead-of-javascript , but when I have tried them there were errors.
I have try to post a view to
response = db.post("_temp_view", <<EOJS)
function(doc){
return doc
}
}
EOJS
Infact, I have this problem:
#<CouchObject::Response:0xb6deb370 @response=#<Net::HTTPInternalServerError 500 Internal Server Error readbody=true>, @parsed_body={"error"=>"query_language_unknown", "reason"=>"application/json"}>
In any case I would prefer to use ruby instead of javascript to query couchdb.
Can you halp me?
Thanks
Paola
Scopri il blog di Yahoo! Mail:
Trucchi, novità e la tua opinione.
http://www.ymailblogit.com/blog
Re: create views, ruby instead of javascript
Posted by kowsik <ko...@gmail.com>.
You need to include additional headers in the POST request to indicate
that the view language is JSON, like so:
db.post('_temp_view', <<EOJS, 'content-type' => 'application/json')
function(doc) {
...
}
EOJS
Dunno know if couch_object supports this, but you can use Net::HTTP to
do the same thing:
Net::HTTP.start(host, port) do |http|
http.post('/' + dbname + '/_temp_view', <<-EOJS, 'content-type' =>
'application/json')
function(doc) {
...
}
EOJS
end
K.
On Sun, Oct 5, 2008 at 1:47 PM, Paola Lorusso <lo...@yahoo.it> wrote:
> Hi ,
> I' am trying to use couchdb with ruby. I am using in particular 'couch_object' to interface ruby with couchdb.
> I would ask how I can create views in ruby instead of javascript to query couchdb.
> In particular I am interested to faster this query following below that queries a blog db, where I have posted comments, posts, and authors.
>
>
> results1 = Array.new
> for post in posts
> id = post["id"]
> doc = db.get(id).to_document
> if doc["type"] == 'post' and doc["title"][0..1]== /xr/ then results1 = doc end
> end
>
> I have read samewhere that I can optimize the performance using views. May I do that following this example?
>
> I have seen same exemples on this URL http://theexciter.com/articles/couchdb-views-in-ruby-instead-of-javascript , but when I have tried them there were errors.
>
> I have try to post a view to
> response = db.post("_temp_view", <<EOJS)
> function(doc){
> return doc
> }
> }
> EOJS
>
> Infact, I have this problem:
> #<CouchObject::Response:0xb6deb370 @response=#<Net::HTTPInternalServerError 500 Internal Server Error readbody=true>, @parsed_body={"error"=>"query_language_unknown", "reason"=>"application/json"}>
>
> In any case I would prefer to use ruby instead of javascript to query couchdb.
>
> Can you halp me?
> Thanks
>
> Paola
>
>
>
> Scopri il blog di Yahoo! Mail:
> Trucchi, novità e la tua opinione.
> http://www.ymailblogit.com/blog
Re: create views, ruby instead of javascript
Posted by Johan Sørensen <jo...@johansorensen.com>.
Hi,
On Sun, Oct 5, 2008 at 10:47 PM, Paola Lorusso <lo...@yahoo.it> wrote:
> Hi ,
> I' am trying to use couchdb with ruby. I am using in particular 'couch_object' to interface ruby with couchdb.
> I would ask how I can create views in ruby instead of javascript to query couchdb.
> In particular I am interested to faster this query following below that queries a blog db, where I have posted comments, posts, and authors
[..]
> I have seen same exemples on this URL http://theexciter.com/articles/couchdb-views-in-ruby-instead-of-javascript , but when I have tried them there were errors.
The particular ruby view server that shipped with CouchObject was
based on couchdb as it stood pre-7.0 iirc. Hence it's quite out of
date now, and has since been removed from the CouchObject
distribution. I personally like javascript myself, so I don't see
myself updating the ruby view server...
If you want to give it a go, look at main.js in the CouchDB source and
port it over to ruby.
Cheers,
JS