Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Let’s explore CouchDB from the REPL, starting with the basics: creating, updating, and deleting documents.
Example 15-1. Simple CouchDB interaction in a REPL
(use '[com.ashafa.clutch :only (create-database with-db put-document
get-document delete-document)
:as clutch])
(def db (create-database "repl-crud"))
(put-document db {:_id "foo" :some-data "bar"})
;= {:_rev "1-2bd2719826", :some-data "bar", :_id "foo"}
(put-document db (assoc *1 :other-data "quux"))
;= {:other-data "quux", :_rev "2-9f29b39770", :some-data "bar", :_id "foo"}
(get-document db "foo")
;= {:_id "foo", :_rev "2-9f29b39770", :other-data "quux", :some-data "bar"}
(delete-document db *1)
;= {:ok true, :id "foo", :rev "3-3e98dd1028"}
(get-document db "foo")
;= nil