seancorfield / honeysql

Turn Clojure data structures into SQL
https://cljdoc.org/d/com.github.seancorfield/honeysql/CURRENT
1.77k stars 174 forks source link

Add an option to bypass double question mark #533

Closed igrishaev closed 5 months ago

igrishaev commented 5 months ago

As I mentioned in Slack, I use HoneySQL to generate a JSONpath expression for Postgres. JSONpath has got its own atmosphere, for example, it has the ? operator to filter the left part with a subquery:

$.track.segments[*].HR ? (@ > 130)

$.track.segments[*] ? (@.location[1] < 13.4) ? (@.HR > 130)."start time"

The thing is, whenever one uses the :? operator in HoneySQL, it produces a double ?? sign to comply with JDBC quoting rules.

At the moment, I've figured out with a crutch like this:

(def BLANK (keyword ""))

(sql/register-op! BLANK)

(defn ?-op [field1 field2]
  [BLANK field1 [:raw "?"] field2])

which produces

... field1 ? field2

I believe it would be nice to have an extra flag for the format function to bypass quoting the question mark. For example:

(honey.sql/format {sql-map} {:skip-?-quoting true})

or similar. The naming is completely up to you, I don't have any preferences. A dynamic var is also fine (just in case it's easier to tweak this behaviour with a dynamic var).

Links: