honeysql

Discussion of https://github.com/seancorfield/honeysql :slightly_smiling_face:
2021-02-25T21:29:24.035800Z

well, this is curious…

(honeysql.helpers/columns (honeysql.core/raw "col1") (honeysql.core/raw "\"col.2\"") (honeysql.core/raw "col.3"))
=> #sql/raw"col1"
(honeysql.helpers/columns (keyword "col1") (honeysql.core/raw "\"col.2\"") (honeysql.core/raw "col.3"))
=> {:columns (:col1 #sql/raw"\"col.2\"" #sql/raw"col.3")}

seancorfield 2021-02-25T21:33:24.036900Z

Yeah, I suspect there's an edge case with merging data on that first column. Put {} before the first column name.

2021-02-25T21:34:00.037100Z

aha, yep, that did it

2021-02-25T21:34:13.037400Z

better than what I was planning

seancorfield 2021-02-25T21:34:25.037600Z

user=> (columns (sql/raw "col1") (sql/raw "col.two") (sql/raw "col:three"))
#sql/raw "col1"
user=> (columns {} (sql/raw "col1") (sql/raw "col.two") (sql/raw "col:three"))
{:columns (#sql/raw "col1" #sql/raw "col.two" #sql/raw "col:three")}

seancorfield 2021-02-25T21:34:38.038Z

Normally you'd thread a hash map into the helper call.

seancorfield 2021-02-25T21:35:21.038200Z

user=> (-> {} (columns (sql/raw "col1") (sql/raw "col.two") (sql/raw "col:three")))
{:columns (#sql/raw "col1" #sql/raw "col.two" #sql/raw "col:three")}

seancorfield 2021-02-25T21:35:42.038700Z

Nearly all the helpers expect to be used in that context.

2021-02-25T21:35:54.039Z

ah, right. hence the insert-into example from the README

seancorfield 2021-02-25T21:36:46.039300Z

HoneySQL v2 gets it right:

user=> (columns [:raw "col1"] [:raw "col.two"] [:raw "col:three"])
{:columns [[:raw "col1"] [:raw "col.two"] [:raw "col:three"]]}

2021-02-25T22:26:37.039800Z

thanks a lot, Sean! this is extremely helpful. I will definitely be looking for us to upgrade to v2 once it’s released 🙂

2021-02-25T22:28:06.040800Z

in the meantime, I can finally explain the hiccup we ran into in the 0.9.4->1.0.461 upgrade in 0.9.4:

(honeysql.helpers/columns {} (honeysql.core/raw "col1"))
=> {:columns (#sql/raw"col1")}
(honeysql.helpers/columns (honeysql.core/raw "col1"))
=> {:columns (#sql/raw"col1")}
in 1.0.461:
(honeysql.helpers/columns (honeysql.core/raw "a.b"))
=> #sql/raw"a.b"
(honeysql.helpers/columns {} (honeysql.core/raw "a.b"))
Execution error (IllegalArgumentException) at honeysql.helpers/check-varargs (helpers.cljc:264).
columns takes varargs, not a single collection

2021-02-25T22:28:31.041200Z

so now that I clearly understand it, I can work around

seancorfield 2021-02-25T23:38:57.042Z

Ah, back in 0.9.7... yeah, with hindsight there was a lot more churn in the 0.9.x releases than there should have been and definitely not enough test coverage 😞

seancorfield 2021-02-25T23:40:29.043300Z

FYI, re: 2.0 -- the main thing blocking a "gold" release is actually documentation, to be honest. At this point the functionality isn't going to change (beyond supporting more ANSI SQL and probably more PostgreSQL syntax).

seancorfield 2021-02-25T23:40:51.043700Z

(but I understand some folks are reluctant to use an alpha in production)