Permalink
Browse files

use a cleaner method to create maps for design documents

  • Loading branch information...
obi-a committed Aug 22, 2014
1 parent 5348ea4 commit 042d333713ad6821984e3fe2a2183563135d8e8d
Showing with 20 additions and 21 deletions.
  1. +10 −5 README.md
  2. +1 −1 project.clj
  3. +9 −15 test/little_couch/core_test.clj
View
@@ -107,13 +107,18 @@ The edited version of the document will be:
Create a design document
```clojure
(def document (assoc-in {:language "javascript"}
[:views :by_gender :map]
"function(doc){ if(doc.gender) emit(doc.gender); }"))
document
;; => {:language "javascript",
;; :views
;; {:by_gender
;; {:map "function(doc){ if(doc.gender) emit(doc.gender); }"}}}
(create-doc x
"_design/my_doc"
{:language "javascript"
:views {
:by_gender {
:map "function(doc){ if(doc.gender) emit(doc.gender); }"
}}})
document)
;; => {:ok true, :id "_design/my_doc", :rev "3-222b1f1716a195012fa291750e742e8e"}
```
Query a permanent view
View
@@ -1,4 +1,4 @@
(defproject little-couch "0.1.0"
(defproject little-couch "0.1.1"
:description "Simple Clojure interface to CouchDB"
:url "https://github.com/obi-a/little-couch"
:license {:name "Eclipse Public License"
@@ -181,21 +181,15 @@
(create-doc x "martin" {:firstname "martin", :state "new york", :gender "male", :city "manhattan", :age 29})
(create-doc x "nancy" {:firstname "nancy", :state "new york", :gender "female", :city "bronx", :age 25})
(create-doc x "susan" {:firstname "susan", :state "new york", :gender "female", :age 35, :fullname ["susan", "Lee"]})
(create-doc x "_design/my_doc" {:language "javascript",
:views {
:by_gender {
:map "function(doc){ if(doc.gender) emit(doc.gender); }"
}}})
(create-doc x "_design/ages" {:language "javascript",
:views {
:people_by_age {
:map "function(doc){ if(doc.age) emit(doc.age); }"
}}})
(create-doc x "_design/gender_city" {:language "javascript",
:views {
:people_by_gender_and_city {
:map "function(doc){ if(doc.gender && doc.city && doc.age) emit([doc.gender, doc.city, doc.age]);}"
}}}))
(create-doc x "_design/my_doc" (assoc-in {:language "javascript"}
[:views :by_gender :map]
"function(doc){ if(doc.gender) emit(doc.gender); }"))
(create-doc x "_design/ages" (assoc-in {:language "javascript"}
[:views :people_by_age :map]
"function(doc){ if(doc.age) emit(doc.age); }"))
(create-doc x "_design/gender_city" (assoc-in {:language "javascript"}
[:views :people_by_gender_and_city :map]
"function(doc){ if(doc.gender && doc.city && doc.age) emit([doc.gender, doc.city, doc.age]);}")))
(testing "view: queries a permanent view"
(let [results (view x "_design/my_doc" "by_gender")]
(is (= 7

0 comments on commit 042d333

Please sign in to comment.