korma / Korma

Tasty SQL for Clojure.
http://sqlkorma.com
1.47k stars 222 forks source link

Support Postgres range types and operators #230

Closed jrobn closed 9 years ago

jrobn commented 10 years ago

Maybe I'm missing something but how do you currently write something similar to:

select name, date
  from reservations r
  where r.period && ['2013/04/01', '2013/04/30']
    and r.room_id = 1234

using postgresql's range operators and syntax in korma without reverting to (exec-raw).

I see in the korma.sql.fns there are predicates defined. I suppose you could extend them to include:

(defn pred-overlaps [k v] (infix k "&&" v))
...

Either that or there needs to be a more flexible way of specifying custom predicates and operators in where and join clauses.

Postgres range functions and operators here: http://www.postgresql.org/docs/current/static/functions-range.html

immoh commented 10 years ago

I don't think there's currently way to write this without exec-raw. The problem with adding the suggested predicate is that it's not standard SQL; in Postgres it means overlap but for example in MySQL it's logical and operator.

I agree that functionality allowing you to specify custom predicates would be useful. Pull requests welcomed.