Skip to content

Commit

Permalink
Added asc and desc functions for order-by
Browse files Browse the repository at this point in the history
  • Loading branch information
weavejester committed Nov 24, 2010
1 parent b9ed10a commit 81f371f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/hassium/core.clj
Expand Up @@ -131,6 +131,16 @@
(let [order (sorting-order fields)]
(Cursor. #(as-mongo-> cursor (.sort order)))))

(defn asc
"Field to be sorted in ascending order."
[field]
{field 1})

(defn desc
"Field to be sorted in descending order."
[field]
{field -1})

(defn save
"Save the map into the collection. The inserted map is returned, with a
generated :_id key if one has not been already set."
Expand Down
2 changes: 1 addition & 1 deletion test/hassium/test/core.clj
Expand Up @@ -46,7 +46,7 @@
(deftest order-by-test
(is (= (map :name @(-> people find-all (order-by :sex)))
["Alice" "Carol" "Bob"]))
(is (= (map :name @(-> people find-all (order-by {:sex -1})))
(is (= (map :name @(-> people find-all (order-by (desc :sex))))
["Bob" "Alice" "Carol"])))

(deftest delete-test
Expand Down

0 comments on commit 81f371f

Please sign in to comment.