lib/couchrest/core/database.rb in jchris-couchrest-0.16 vs lib/couchrest/core/database.rb in jchris-couchrest-0.17.0
- old
+ new
@@ -18,11 +18,11 @@
@server = server
@host = server.uri
@uri = @root = "#{host}/#{name}"
@streamer = Streamer.new(self)
@bulk_save_cache = []
- @bulk_save_cache_limit = 50
+ @bulk_save_cache_limit = 500 # must be smaller than the uuid count
end
# returns the database's uri
def to_s
@uri
@@ -59,29 +59,34 @@
# Query a CouchDB view as defined by a <tt>_design</tt> document. Accepts
# paramaters as described in http://wiki.apache.org/couchdb/HttpViewApi
def view(name, params = {}, &block)
keys = params.delete(:keys)
- url = CouchRest.paramify_url "#{@uri}/_view/#{name}", params
+ name = name.split('/') # I think this will always be length == 2, but maybe not...
+ dname = name.shift
+ vname = name.join('/')
+ url = CouchRest.paramify_url "#{@uri}/_design/#{dname}/_view/#{vname}", params
if keys
CouchRest.post(url, {:keys => keys})
else
if block_given?
- @streamer.view(name, params, &block)
+ @streamer.view("_design/#{dname}/_view/#{vname}", params, &block)
else
CouchRest.get url
end
end
end
# GET a document from CouchDB, by id. Returns a Ruby Hash.
- def get(id)
+ def get(id, params = {})
slug = escape_docid(id)
- hash = CouchRest.get("#{@uri}/#{slug}")
- doc = if /^_design/ =~ hash["_id"]
- Design.new(hash)
+ url = CouchRest.paramify_url("#{@uri}/#{slug}", params)
+ result = CouchRest.get(url)
+ return result unless result.is_a?(Hash)
+ doc = if /^_design/ =~ result["_id"]
+ Design.new(result)
else
- Document.new(hash)
+ Document.new(result)
end
doc.database = self
doc
end