honeysql

Discussion of https://github.com/seancorfield/honeysql :slightly_smiling_face:
2019-11-06T14:48:12.001Z

I was wondering, is there a way to make sql/format output non prepared statements?

2019-11-06T14:48:32.001500Z

it's just useful for debugging sometimes to use non prepared statements, but looking at the code I don't see a way to do that now

2019-11-06T14:48:58.002400Z

is there another way to transform prepared SQL statements into "regular" SQL statements?

seancorfield 2019-11-06T16:57:21.003400Z

HoneySQL does not produce "prepared statements", it just produces data.

2019-11-06T17:05:49.003900Z

uhm I mean something like

(sql/format (load-players-sql 100))
["SELECT * FROM player pl INNER JOIN league_players lg ON pl.id = lg.player_id WHERE lg.league_id = ?"
 100]

2019-11-06T17:06:25.004700Z

isn't that a prepared statement?

seancorfield 2019-11-06T17:29:45.005300Z

That's just data.

seancorfield 2019-11-06T17:30:06.005800Z

Libraries like clojure.java.jdbc and next.jdbc create PreparedStatements.

seancorfield 2019-11-06T17:32:39.007800Z

You can use (types/inline 100) (where types is honeysql.types) to tell HoneySQL to inline the value -- but bear in mind it does not know how to convert Clojure data to SQL values (that's up to the JDBC driver) so inline is a pure textual substitution, so you need to take care of quoting SQL strings etc.

seancorfield 2019-11-06T17:34:51.009300Z

HoneySQL just converts Clojure data structures into a vector containing a SQL query/command string and pulls all the "loose" Clojure data values out into that vector. clojure.java.jdbc and next.jdbc create prepared statements from that SQL string and add in the values as parameters, but it is the JDBC driver that does all of the conversion.