honeysql

Discussion of https://github.com/seancorfield/honeysql :slightly_smiling_face:
Adrian Smith 2020-07-29T09:03:59.297200Z

in the format.cljc file where is to-sql defined?

kwrooijen 2020-07-29T09:07:18.298200Z

to-sql is part of the ToSql protocol, and you need to implement it for different types https://github.com/seancorfield/honeysql#why-does-my-parameter-get-emitted-as-

Adrian Smith 2020-07-29T09:29:41.301400Z

ah ok and is line 407 the implementations for each type of dispatch? I was wondering how it all comes together because I can run (to-sql [:select :*]) and get "SELECT *" I think my question is what handles the recursion?

kwrooijen 2020-07-29T09:37:40.302600Z

I'm not too familiar with the HoneySQL code base, but it's probably defined in here https://github.com/seancorfield/honeysql/blob/1e45fdff282436cce1e1c0aefdd8d912c1f58af0/src/honeysql/format.cljc#L407 I assume it's one of the clauses that uses this function https://github.com/seancorfield/honeysql/blob/1e45fdff282436cce1e1c0aefdd8d912c1f58af0/src/honeysql/format.cljc#L374

kwrooijen 2020-07-29T09:39:12.303100Z

Though I might be completely missing the mark 🙂

👍 1
kirill.salykin 2020-07-29T15:25:10.304200Z

goodday! Please help I am trying to update jsonb field with such query

(sql/format {:update :table
    :set {:column [{:a 1}]}
    :where [:= :id 1]})
but format complaints about wrong alias --- if I use honeysql.format/value - it is still incorrect
(sql/format {:update :table
    :set {:column (f/value [{:a 1}])}
    :where [:= :id 1]})
produces
["UPDATE table SET column = (?) WHERE id = ?" {:a 1} 1]
It is map, not vector is there a way to do so w/o using json-string? thanks

seancorfield 2020-07-29T15:51:30.305600Z

@kirill.salykin I don't know what you'll have to do in HoneySQL but using JSONB (in PostgreSQL) with JDBC is covered in the Tips & Tricks section of the next.jdbc docs.

seancorfield 2020-07-29T15:52:40.307Z

HoneySQL makes a number of assumptions about the structure of the data used in the DSL and some of those assumptions don't seem to be compatible with PostgreSQL's structured data types -- HoneySQL primarily aims to support ANSI SQL only.

kirill.salykin 2020-07-29T15:52:42.307100Z

I have all this in place

kirill.salykin 2020-07-29T15:53:04.307500Z

ok, so seems generating json string is the answer

kirill.salykin 2020-07-29T15:53:05.307700Z

thsanks!

seancorfield 2020-07-29T15:53:56.308300Z

You might try inserting a CAST operation which might prevent HoneySQL from interfering with your value...

seancorfield 2020-07-29T15:54:30.308900Z

(when I write HoneySQL 2.0 or next.honey or whatever I call it, this is an area I plan to address)

kirill.salykin 2020-07-29T16:21:32.309700Z

what I did is (sql/call :cast (json/generate-string …) :json)

1
seancorfield 2020-07-29T16:28:15.310700Z

Not "ideal" but a reasonable workaround for HoneySQL perhaps.

👍 1