honeysql

Discussion of https://github.com/seancorfield/honeysql :slightly_smiling_face:
henrik 2017-07-18T06:38:50.981836Z

[honeysql "0.9.0"] and [nilenso/honeysql-postgres "0.2.3"]

henrik 2017-07-18T06:41:30.018604Z

I managed to get around it. If I keyword the number, it’s inlined:

(-> (pg-helpers/create-table :cities)
    (pg-helpers/with-columns [[:city (sql/call :varchar :80) (sql/call :primary-key)]
                              [:location :point]])
    sql/format)
`
[“CREATE TABLE cities (city varchar(80) PRIMARY KEY, location point)“] 

henrik 2017-07-18T06:42:45.035743Z

I don’t :refer :all, maybe that has something to do with it:

;; SQL machinery
    [honeysql.core :as sql]
    [honeysql.helpers :as sql-helpers]
    [honeysql.format :as sql-format]
    [honeysql-postgres.format :as pg-format]
    [honeysql-postgres.helpers :as pg-helpers]
    [clj-postgresql.core :as pg]
    [clojure.java.jdbc :as jdbc]
`

seancorfield 2017-07-18T16:35:44.978832Z

@henrik So it may be a difference between HoneySQL 0.6.3 which is the default for honeysql-postgres and HoneySQL 0.9.0 which you're using.

seancorfield 2017-07-18T16:40:39.152594Z

Yes, confirmed: HoneySQL 0.2.3 inlines numeric parameters but HoneySQL 0.9.0 lifts them out as separate parameters.

👍 1
seancorfield 2017-07-18T16:46:59.379747Z

@michaelblume Do you know if there is a way to tell HoneySQL "inline this -- it's not a parameter"?

2017-07-18T17:47:54.541508Z

@seancorfield I don’t think there is right now

seancorfield 2017-07-18T17:50:01.617723Z

@michaelblume I'm curious as to why it doesn't inline the keyword value -- and wondering whether that's a "safe" workaround?

seancorfield 2017-07-18T17:51:09.659560Z

I was a bit surprised that 0.2.3 inlined numeric values but lifted strings -- later versions lift numeric values to parameters.

2017-07-18T18:03:45.125380Z

aha, I see the problem

2017-07-18T18:04:49.163846Z

we’re treating numbers as parameterized values because otherwise NaN, -Infinity, and Infinity will insert badly

2017-07-18T18:05:21.182881Z

change introduced in 0.7.0

seancorfield 2017-07-18T18:06:26.221626Z

And that's good -- otherwise we'd get ["SELECT * FROM foo WHERE id = 123"] which would not benefit from parameterization for different id values.

seancorfield 2017-07-18T18:06:58.239995Z

(you want the prepared statement to have ...WHERE id = ? so it can be reused for other values)

2017-07-18T18:07:22.254342Z

right

2017-07-18T18:07:30.259029Z

so maybe we need to introduce an Inline record type

2017-07-18T18:07:37.262547Z

that you could wrap the 80 in

seancorfield 2017-07-18T18:08:01.277298Z

Yeah. Keyword seems to "work" but seems a bit hokey.

2017-07-18T18:08:08.280889Z

it does yeah

seancorfield 2017-07-18T18:10:22.360528Z

https://github.com/jkk/honeysql/issues/171 and we can think about / discuss it.

2017-07-18T18:30:42.092776Z

https://github.com/jkk/honeysql/pull/172

seancorfield 2017-07-18T18:58:39.088961Z

That's nice and clean!

2017-07-18T19:51:14.832828Z

thanks =)