Permalink
Browse files

added fetch-one, extracted out karras.sugar, added documentation and …

…an example
  • Loading branch information...
1 parent 4dcec7b commit 3acb791c838ed33ccca60fecf6baa27bdbc0022a @wilkes committed Jan 17, 2010
Showing with 387 additions and 112 deletions.
  1. +21 −0 LICENSE
  2. +46 −6 README
  3. +159 −106 src/karras.clj
  4. +69 −0 src/karras/example.clj
  5. +92 −0 src/karras/sugar.clj
View
@@ -0,0 +1,21 @@
+The MIT License
+
+Copyright (c) 2010 Wilkes Joiner
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
View
@@ -1,15 +1,55 @@
-# candygram
+# karras
"Mongo like candy!", Blazing Saddles
## Usage
-FIXME: write
+(use 'karras)
+(use 'karras.sugar)
-## Installation
+(def my-collection (collection (connect) :my-database :my-collection))
-FIXME: write
+(def doc1 {:name "doc11" :author "author1" :counter 0 :size 10})
+(def doc2 {:name "doc12" :author "author1" :counter 0 :size 20})
+(def doc3 {:name "doc21" :author "author2" :counter 0 :size 30})
+(def doc1 {:name "doc22" :author "author2" :counter 0 :size 40})
+(def doc2 {:name "doc31" :author "author3" :counter 0 :size 50})
+(def doc3 {:name "doc31" :author "author3" :counter 0 :size 60})
-## License
+(insert my-collection doc1 doc2 doc3)
-FIXME: write
+(ensure-index my-collection (asc :size))
+(ensure-index my-collection (compound-index (asc :name) (desc :author))
+
+(def all-ordered-by-author-then-title
+ (fetch my-collection
+ :order-by [(asc :author) (asc :title)]))
+
+(def all-with-size-more-than-20
+ (fetch my-collection (query (gte :size 20))))
+
+(def increment-all-counters
+ (update-all my-collection (modify (incr :counter))))
+
+(def tag-big-if-size-gte-30
+ (update-all my-collection (query (gte :size 30))
+ (modify (push :tags "big"))))
+
+(def count-all-documents (count-docs my-collection))
+
+(defn count-for-author [author]
+ (count-docs (query (eq :author author))))
+
+(def sum-of-counters
+ (group my-collection
+ []
+ nil
+ {:csum 0}
+ "function(doc,result) { result.csum += doc.counter; }"))
+
+(defn sum-of-counters-tagged-docs-group-by-author [author]
+ (group my-collection
+ [:author]
+ (query (exist? :tags))
+ {:csum 0}
+ "function(doc,result) { result.csum += doc.counter; }"))
Oops, something went wrong.

0 comments on commit 3acb791

Please sign in to comment.