Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Let `in` predicate accept any seq #99

Merged
merged 1 commit into from

2 participants

@lynaghk

I was surprised that when I passed a list into in:

(-> tbl
    (select (where (in :column a_list))))

the compiled SQL only contained the first element of the list.
I dug into the source and found that it was because prefix operators check their arguments with vector?.
I changed this to the more general seq?, and it seems to work fine for me (both in the REPL, and all of the tests pass when running cake test).

@bendlas
Collaborator

Thanks for the PR.

Unfortunately, seq? is not a generalization of vector? because it returns false on vectors. The function you might have been looking for is sequential?.
Also, there is no testcase for IN, that would have caught that.

Would you mind adding test cases and correcting the code?

kind regards

@lynaghk

Thanks for the catch! I just started with Clojure, and I probably shouldn't be submitting pull requests at 10 p.m. anyway = )

I've amended the commit to use coll? and updated the test cases to try passing a vector, list, and set to in.

@bendlas
Collaborator

That seems to work fine, thanks!

@bendlas bendlas merged commit 3b5eadf into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
2  src/clojureql/predicates.clj
@@ -84,7 +84,7 @@
:stmt (conj stmt (format "%s %s (%s)"
(nskeyword field)
(upper-name op)
- (->> (if (vector? (first expr))
+ (->> (if (coll? (first expr))
(first expr)
expr)
parameterize
View
8 test/clojureql/test/predicates.clj
@@ -37,4 +37,10 @@
(not* (or* (<* :id 100) (>* :id 101)))
["NOT(((id < ?) OR (id > ?)))" [100 101]]
(not* (or* (=* :id 5) (not* (like :name "frank%"))))
- ["NOT(((id = ?) OR NOT((name LIKE ?))))" [5 "frank%"]]))
+ ["NOT(((id = ?) OR NOT((name LIKE ?))))" [5 "frank%"]]
+ (in :x [1 2])
+ ["x IN (?,?)" [1 2]]
+ (in :x '(1 2))
+ ["x IN (?,?)" [1 2]]
+ (in :x #{1 2})
+ ["x IN (?,?)" [1 2]]))
Something went wrong with that request. Please try again.