honeysql

Discussion of https://github.com/seancorfield/honeysql :slightly_smiling_face:
Ilan Uzan 2021-06-27T07:46:53.086Z

I am trying to use :param inside :raw because I have an unsupported SQL clause postgres:

(sql/format {:select [:*]
             :from [:blah]
             :where [:raw ["x >>= " [:param :x]]]})
I don't get where to place the param value - this throws:
missing parameter value for :x
and what worked in honeysql-1:
(sql/format {:select [:*]
             :from [:blah]
             :where [:raw ["x >>= " [:param :x]]] :params {:x 3}})
Execution error (ExceptionInfo) at honey.sql/format-dsl (sql.cljc:904).
These SQL clauses are unknown or have nil values: :params
does not work in honeysql-2...

Ilan Uzan 2021-06-27T16:13:10.088300Z

nevermind, it works - my code wasn't doing what I thought it was doing.

👍 1
seancorfield 2021-06-27T17:44:49.089500Z

Just to follow-up on @ilan800’s post -- this works:

dev=> (sql/format {:select [:*]
 #_=>              :from [:blah]
 #_=>              :where [:raw ["x >>= " [:param :x]]]}
 #_=>             {:params {:x 3}})
["SELECT * FROM blah WHERE x >>= ?" 3]
but it's easy enough to just register >>= as a new binary operator and use it directly:
dev=> (sql/register-op! '>>=)
nil
dev=> (sql/format {:select [:*]
 #_=>              :from [:blah]
 #_=>              :where [:>>= :x [:param :x]]}
 #_=>             {:params {:x 3}})
["SELECT * FROM blah WHERE x >>= ?" 3]

Ilan Uzan 2021-06-28T07:28:37.089800Z

even better! thanks:)