Skip to content
This repository has been archived by the owner on Dec 7, 2018. It is now read-only.

Commit

Permalink
Allow WHERE expression as a vector. Also fixes #2
Browse files Browse the repository at this point in the history
  • Loading branch information
kofrasa committed Apr 13, 2015
1 parent 17d3d15 commit 8937434
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
/target
/lib
/classes
Expand Down
4 changes: 3 additions & 1 deletion src/java_jdbc/sql.clj
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ and update! high-level operations within clojure.java.jdbc directly." }
[param-map & {:keys [entities] :or {entities as-is}}]
(let [ks (keys param-map)
vs (vals param-map)]
(if (vector? param-map)
param-map
(cons (str/join
" AND "
(map (fn [k v]
Expand All @@ -307,4 +309,4 @@ and update! high-level operations within clojure.java.jdbc directly." }
(str " IN (" (str/join ", " (repeat (count v) "?")) ")")
(if (nil? v) " IS NULL" " = ?"))))
ks vs))
(remove nil? (flatten vs)))))
(remove nil? (flatten vs))))))
1 change: 1 addition & 0 deletions test/java_jdbc/sql_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
(select * :a (join :b {:a.id :b.id}) (join :c {:c.id :b.id})))))

(deftest where-dsl
(is (= ["id = ?" 1] (where ["id = ?" 1])))
(is (= ["id = ?" 42] (where {:id 42})))
(is (= ["id IS NULL"] (where {:id nil})))
(is (= ["id IN (?, ?, ?, ?, ?, ?)" 4 8 15 16 23 42] (where {:id [4 8 15 16 23 42]})))
Expand Down

0 comments on commit 8937434

Please sign in to comment.