honeysql

Discussion of https://github.com/seancorfield/honeysql :slightly_smiling_face:
2017-11-10T21:14:51.000462Z

Hi folks, how would you generate "select 1 < 2" with honeysql? I'd have expected it to be {:select [:&lt; 1 2]} but that yields ["SELECT &lt;, ?, ?" 1 2].

seancorfield 2017-11-10T21:34:53.000354Z

@cddr I'm pretty sure for something like that you'd need the sql/raw function? {:select (sql/raw "1 &lt; 2")}

seancorfield 2017-11-10T21:35:42.000078Z

(where sql is an alias for honeysql.core)

seancorfield 2017-11-10T21:36:08.000416Z

I think you could also do {:select #sql/raw "1 &lt; 2"} -- I believe there's a data reader for that...?

2017-11-10T21:37:18.000435Z

Cool. Thanks

bja 2017-11-10T22:13:30.000286Z

{:select [(honeysql.core/call :&lt; 1 2)]}

bja 2017-11-10T22:14:18.000408Z

honeysql.core/call is used to invoke SQL functions. The first argument is the function name as a keyword

seancorfield 2017-11-10T22:31:17.000168Z

@bja call will substitute parameters

seancorfield 2017-11-10T22:31:34.000318Z

(format (select (call :&lt; 1 2)))
=&gt; ["SELECT ? &lt; ?" 1 2]

seancorfield 2017-11-10T22:33:02.000134Z

even with brackets and the raw map

(format {:select [(call :&lt; 1 2)]})
=&gt; ["SELECT ? &lt; ?" 1 2]

seancorfield 2017-11-10T22:35:16.000090Z

raw works

(format {:select [#sql/raw "1 &lt; 2"]})
=&gt; ["SELECT 1 &lt; 2"]
but it's kinda ugly (I assume this is part of a larger query @cddr?)

2017-11-10T22:36:15.000345Z

Yeah. Surprised I haven't run into this before

seancorfield 2017-11-10T22:36:59.000083Z

I think older versions of HoneySQL did not lift parameters in some situations -- but that was a bug.

seancorfield 2017-11-10T22:37:11.000118Z

So you may have gotten away with it on older versions 🙂