Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

15. Using Nonrelational Databases > Basic CRUD Operations

Basic CRUD Operations

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"))                                1

(put-document db {:_id "foo" :some-data "bar"})                       2
;= {:_rev "1-2bd2719826", :some-data "bar", :_id "foo"}
(put-document db (assoc *1 :other-data "quux"))                       3
;= {:other-data "quux", :_rev "2-9f29b39770", :some-data "bar", :_id "foo"}
(get-document db "foo")                                               4
;= {:_id "foo", :_rev "2-9f29b39770", :other-data "quux", :some-data "bar"}
(delete-document db *1)                                               5
;= {:ok true, :id "foo", :rev "3-3e98dd1028"}
(get-document db "foo")                                               6
;= nil

  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial