Fork me on GitHub
#honeysql
<
2021-06-27
>
Ilan Uzan07:06:53

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 Uzan16:06:10

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

👍 3
seancorfield17:06:49

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 Uzan07:06:37

even better! thanks:)