Skip to content

Commit 2e7ce63

Browse files
author
Josh Marchán
committed
Got rid of :uri kwarg for db-request.
1 parent 1a30571 commit 2e7ce63

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

src/db.lisp

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,9 @@ with a particular CouchDB database.")
172172
;; TODO - CouchDB places restrictions on what sort of URLs are accepted, such as everything having
173173
;; to be downcase, and only certain characters being accepted. There is also special meaning
174174
;; behing the use of /, so a mechanism to escape it in certain situations would be good.
175-
(defmessage db-request (db &key)
175+
(defmessage db-request (db uri &key)
176176
(:documentation "Sends a CouchDB request to DB.")
177-
(:reply ((db =database=) &rest all-keys &key (uri ""))
177+
(:reply ((db =database=) uri &rest all-keys)
178178
(apply #'couch-request (server db) (strcat (name db) "/" uri) all-keys)))
179179

180180
(defmacro handle-request ((result-var request) &body expected-responses)
@@ -193,7 +193,7 @@ keywords."
193193
(defmessage db-info (db)
194194
(:documentation "Fetches info about a given database from the CouchDB server.")
195195
(:reply ((db =database=))
196-
(handle-request (response (db-request db))
196+
(handle-request (response (db-request db ""))
197197
(:ok response)
198198
(:internal-server-error (error "Illegal database name: ~A" (name db)))
199199
(:not-found (error 'db-not-found :uri (db-namestring db))))))
@@ -208,7 +208,7 @@ that can be used to perform operations on it."
208208
(defun create-db (name &key (prototype =database=) (server =json-server=))
209209
"Creates a new CouchDB database. Returns a database object that can be used to operate on it."
210210
(let ((db (create prototype 'server server 'name name)))
211-
(handle-request (response (db-request db :method :put))
211+
(handle-request (response (db-request db "" :method :put))
212212
(:created db)
213213
(:internal-server-error (error "Illegal database name: ~A" name))
214214
(:precondition-failed (error 'db-already-exists :uri (db-namestring db))))))
@@ -222,20 +222,20 @@ that can be used to perform operations on it."
222222
(defmessage delete-db (db &key)
223223
(:documentation "Deletes a CouchDB database.")
224224
(:reply ((db =database=) &key)
225-
(handle-request (response (db-request db :method :delete))
225+
(handle-request (response (db-request db "" :method :delete))
226226
(:ok response)
227227
(:not-found (error 'db-not-found :uri (db-namestring db))))))
228228

229229
(defmessage compact-db (db)
230230
(:documentation "Triggers a database compaction.")
231231
(:reply ((db =database=))
232-
(handle-request (response (db-request db :uri "_compact" :method :post))
232+
(handle-request (response (db-request db "_compact" :method :post))
233233
(:accepted response))))
234234

235235
(defmessage changes (db)
236236
(:documentation "Returns the changes feed for DB")
237237
(:reply ((db =database=))
238-
(handle-request (response (db-request db :uri "_changes"))
238+
(handle-request (response (db-request db "_changes"))
239239
(:ok response))))
240240

241241
;;;
@@ -244,7 +244,7 @@ that can be used to perform operations on it."
244244
(defmessage get-document (db id)
245245
(:documentation "Returns an CouchDB document from DB as an alist.")
246246
(:reply ((db =database=) id)
247-
(handle-request (response (db-request db :uri id))
247+
(handle-request (response (db-request db id))
248248
(:ok response)
249249
(:not-found (error 'document-not-found :db db :id id)))))
250250

@@ -255,22 +255,21 @@ that can be used to perform operations on it."
255255
(when endkey (push `("endkey" . ,(prin1-to-string endkey)) params))
256256
(when limit (push `("limit" . ,(prin1-to-string limit)) params))
257257
(when include-docs (push `("include_docs" . "true") params))
258-
(handle-request (response (db-request db :uri "_all_docs" :parameters params))
258+
(handle-request (response (db-request db "_all_docs" :parameters params))
259259
(:ok response))))
260260

261261
(defmessage batch-get-documents (db &rest doc-ids)
262262
(:documentation "Uses _all_docs to quickly fetch the given DOC-IDs in a single request.")
263263
(:reply ((db =database=) &rest doc-ids)
264-
(handle-request (response (db-request db :uri "_all_docs" :method :post
264+
(handle-request (response (db-request db "_all_docs" :method :post
265265
:parameters '(("include_docs" . "true"))
266266
:content (format nil "{\"foo\":[~{~S~^,~}]}" doc-ids)))
267267
(:ok response))))
268268

269269
(defmessage put-document (db id doc &key)
270270
(:documentation "Puts a document into DB, using ID.")
271271
(:reply ((db =database=) id doc &key batch-ok-p)
272-
(handle-request (response (db-request db :uri id :method :put
273-
:content doc
272+
(handle-request (response (db-request db id :method :put :content doc
274273
:parameters (when batch-ok-p '(("batch" . "ok")))))
275274
((:created :accepted) response)
276275
(:conflict (error 'document-conflict :id id :doc doc)))))
@@ -281,21 +280,20 @@ document does not already exist. Note that using this function is discouraged in
281280
documentation, since it may result in duplicate documents because of proxies and other network
282281
intermediaries.")
283282
(:reply ((db =database=) doc)
284-
(handle-request (response (db-request db :method :post :content doc))
283+
(handle-request (response (db-request db "" :method :post :content doc))
285284
((:created :accepted) response)
286285
(:conflict (error 'document-conflict :doc doc)))))
287286

288287
(defmessage delete-document (db id revision)
289288
(:documentation "Deletes an existing document.")
290289
(:reply ((db =database=) id revision)
291-
(handle-request (response (db-request db :method :delete
292-
:uri (format nil "~A?rev=~A" id revision)))
290+
(handle-request (response (db-request db (format nil "~A?rev=~A" id revision) :method :delete))
293291
(:ok response))))
294292

295293
(defmessage copy-document (db from-id to-id &key)
296294
(:documentation "Copies a document's content in-database.")
297295
(:reply ((db =database=) from-id to-id &key revision)
298-
(handle-request (response (db-request db :uri from-id :method :copy
296+
(handle-request (response (db-request db from-id :method :copy
299297
:additional-headers `(("Destination" . ,to-id))
300298
:parameters `(,(when revision `("rev" . ,revision)))))
301299
(:created response))))

0 commit comments

Comments
 (0)