honeysql

Discussion of https://github.com/seancorfield/honeysql :slightly_smiling_face:
murtaza 2021-03-11T14:49:24.115700Z

👋 We’ve released a new version of honeysql-postgres with support for more PG clauses, minor improvements, and a revamped readme. • https://github.com/nilenso/honeysql-postgres/releases/tag/0.3.104 • https://github.com/nilenso/honeysql-postgres/releases/tag/0.4.112 • https://github.com/nilenso/honeysql-postgres/blob/master/CHANGELOG.md

murtaza 2021-03-11T15:06:29.115900Z

We've also added a note about the progress being made in Honeysql 2.0 for people who may be looking for pg support

seancorfield 2021-03-11T17:17:18.116300Z

https://github.com/seancorfield/honeysql/issues/310 🙂

borkdude 2021-03-11T17:18:46.116800Z

how do I write this?

(sql/format {:update :foo :set {:dismiss "dissmis + 1"}})

borkdude 2021-03-11T17:20:06.117Z

I tend to just go with hugsql for queries like this

borkdude 2021-03-11T17:20:17.117300Z

but there might be a good way to do it in honeysql?

seancorfield 2021-03-11T17:21:40.117600Z

[:+ dissmis 1] is the expression

seancorfield 2021-03-11T17:22:12.117800Z

user=> (sql/format {:update :foo :set {:dismiss [:+ :dissmis 1]}})
["UPDATE foo SET dismiss = dissmis + ?" 1]

seancorfield 2021-03-11T17:23:09.118200Z

@borkdude There's an example of that in the README:

(-> (h/update :films)
    (set {:kind "dramatic"
           :watched [:+ :watched 1]})
    (where [:= :kind "drama"])
    (sql/format {:pretty true}))
=> ["
UPDATE films
SET kind = ?, watched = watched + ?
WHERE kind = ?
"
"dramatic"
1
"drama"]
;; or as pure data DSL:
(-> {:update :films,
     :set {:kind "dramatic", :watched [:+ :watched 1]},
     :where [:= :kind "drama"]}
    (sql/format {:pretty true}))
=> ["
UPDATE films
SET kind = ?, watched = watched + ?
WHERE kind = ?
"
"dramatic"
1
"drama"]

seancorfield 2021-03-11T17:23:31.118500Z

See https://github.com/seancorfield/honeysql/tree/v2#updates

borkdude 2021-03-11T17:23:41.118800Z

I am using v1 still at work.

seancorfield 2021-03-11T17:23:52.119100Z

There's an example in the v1 readme too!

borkdude 2021-03-11T17:24:20.119600Z

my bad then, but thanks for answering :)

seancorfield 2021-03-11T17:24:25.119800Z

You have to use (sql/call :+ :watched 1) in V1 https://github.com/seancorfield/honeysql#updates

borkdude 2021-03-11T17:24:50.120600Z

I see yeah, hm. I did scan the unit tests for this

seancorfield 2021-03-11T17:25:35.121300Z

(I know the V1 readme only uses helpers -- you can always run the helper version in the REPL without sql/format to see what the equivalent data structure would be)

borkdude 2021-03-11T17:26:25.121600Z

thanks a lot, this helps

borkdude 2021-03-11T17:26:42.122Z

I still think the helpers are somewhat magic, but I guess not

seancorfield 2021-03-11T17:27:21.122600Z

They're a lot less "magic" in V2 since they're nearly all implemented with the same generic function 🙂