backwards compatibility for old couchdbs

This commit is contained in:
Chris Anderson 2008-09-13 18:59:24 -04:00
parent f8b80daef6
commit 9e4d5c0eda

View file

@ -64,17 +64,23 @@ module CouchRest
end end
if doc['_id'] if doc['_id']
slug = CGI.escape(doc['_id']) slug = CGI.escape(doc['_id'])
else
slug = doc['_id'] = @server.next_uuid
end
CouchRest.put "#{@root}/#{slug}", doc CouchRest.put "#{@root}/#{slug}", doc
else
begin
slug = doc['_id'] = @server.next_uuid
CouchRest.put "#{@root}/#{slug}", doc
rescue #old version of couchdb
CouchRest.post @root, doc
end
end
end end
def bulk_save docs def bulk_save docs
ids, noids = docs.partition{|d|d['_id']} ids, noids = docs.partition{|d|d['_id']}
uuid_count = [noids.length, @server.uuid_batch_count].max uuid_count = [noids.length, @server.uuid_batch_count].max
noids.each do |doc| noids.each do |doc|
doc['_id'] = @server.next_uuid(uuid_count) nextid = @server.next_uuid(uuid_count) rescue nil
doc['_id'] = nextid if nextid
end end
CouchRest.post "#{@root}/_bulk_docs", {:docs => docs} CouchRest.post "#{@root}/_bulk_docs", {:docs => docs}
end end