in the format.cljc
file where is to-sql
defined?
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-
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?
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
Though I might be completely missing the mark 🙂
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@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.
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.
I have all this in place
ok, so seems generating json string is the answer
thsanks!
You might try inserting a CAST
operation which might prevent HoneySQL from interfering with your value...
(when I write HoneySQL 2.0 or next.honey
or whatever I call it, this is an area I plan to address)
what I did is (sql/call :cast (json/generate-string …) :json)
Not "ideal" but a reasonable workaround for HoneySQL perhaps.