Permalink
Browse files

Support simple map-based WHERE syntax

  • Loading branch information...
mmcgrana committed Jan 26, 2009
1 parent e2ab9a6 commit 249893814fa50ec6a984f0c7fa8c8c463869615f
Showing with 10 additions and 0 deletions.
  1. +7 −0 stash/src/stash/core_sql.clj
  2. +3 −0 stash/test/stash/core_finders_test.clj
@@ -50,6 +50,13 @@
inners (map #(where-exp-sql model %) (rest where-exp))]
(str "(" (str-join conj-str inners)")"))
+ ; {:foo "bar"}
+ (map? where-exp)
+ (let [inners (for [[k v] where-exp]
+ (str "(" (name k) " = "
+ (((quoters-by-name model) k) v) ")"))]
+ (str "(" (str-join " AND " inners) ")"))
+
; [:foo :> 20]
:else
(str "(" (name (where-exp 0)) " "
@@ -34,6 +34,9 @@
(assert=
"SELECT * FROM posts WHERE ((view_count > 3) AND (view_count < 7))"
(find-sql +post+ {:where [:and [:view_count :> 3] [:view_count :< 7]]}))
+ (assert=
+ "SELECT * FROM posts WHERE ((id = 'foo') AND (title = 'bar'))"
+ (find-sql +post+ {:where {:id "foo" :title "bar"}}))
(assert=
(str "SELECT * FROM posts WHERE (view_count > 3) "
"ORDER BY title DESC LIMIT 10 OFFSET 30")

0 comments on commit 2498938

Please sign in to comment.