Commit c7f0a34a5cb5f7a9a7344019089d68ac74e1ba15

  • Tree SHA1: f3aaffe
  • Parent SHA1: d1b4a95 (Added threading when saving has_many relations in case the child does some time consuming task in a call back. Removed ruby2ruby gem which isn't needed at the moment but as a result six specs fail. TODO: move ruby view server to a gem of its own)
  • raw diff | raw patch
Added the posibility of getting raw data back from the view and not only the rows themselves
  
6565 # * CouchObject::Errors::MissingView if the view doesn't exist
6666 #
6767 def query(params = {})
68
69 response = raw_query(params)
70
71 rows_to_return = []
72 response["rows"].each do |params_for_object|
73 rows_to_return << params_for_object["value"]
74 end
75
76 rows_to_return
77
78 end
79
80 #
81 # Returns the response data from CouchDB for a view query without
82 #
83 # Takes:
84 # * [+params+] (hash): a hash of URL query arguments supported
85 # by couchDB. If omitted it defaults to not use a key
86 # and to update the view.
87 #
88 # Example:
89 #
90 # view.raw_query({:update => false, :key => "bar"}) => data
91 #
92 # Returns:
93 # * the response data for the view
94 #
95 # Raises:
96 # * CouchObject::Errors::MissingView if the view doesn't exist
97 #
98 def raw_query(params = {})
99
68100 #Create a querystring with the parameters passed inn
69101 querystring = "?"
70102 params.each_pair do |key, value|
107107
108108 view_with_parameters = name + querystring
109109
110 rows_to_return = []
111
112110 response = JSON.parse(db.get(view_with_parameters).body)
113111
114112 raise CouchObject::Errors::MissingView, \
119119 raise CouchObject::Errors::CouchDBError, \
120120 "CouchDB returned and error and described the problem as #{response['reason']}" \
121121 if response["error"]
122
123 response["rows"].each do |params_for_object|
124 rows_to_return << params_for_object["value"]
125 end
126122
127 rows_to_return
123 return response
128124
129125 end
130126
128128 @db.delete("/#{db.name}/#{name}")
129129 end
130130
131 protected
132 def self.get_db(db)
131 protected
132 def self.get_db(db)
133133 case db.class.to_s
134134 when "CouchObject::Database"
135135 db
140140 "or a CouchObject::Database object"
141141 end
142142 end
143 end
143
144 end
144145end