clojureql select between two dates

316 Views Asked by At

How would I use clojureql to select between two dates? Hopefully something like this:

@(-> (table :abc)
     (select (where (between d1 d2))))
2

There are 2 best solutions below

0
On BEST ANSWER

There is no BETWEEN, and while you might be tempted to use Lisp-y multiple-argument <, that does not work either:

;; invalid SQL output
hello-cql.core> (select (table :abc) (where (< 10 :a 20)))
SELECT abc.* FROM abc WHERE (10 < a < 20)

;; valid SQL output
hello-cql.core> (select (table :abc) (where (and (< 10 :a) (< :a 20))))
SELECT abc.* FROM abc WHERE ((10 < a) AND (a < 20))
0
On

You can write your own between

(defmacro between
  [x min max]
  `(and (< ~min ~x) (< ~x ~max)))

This will be compatible with ClojureQL.