👋 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
We've also added a note about the progress being made in Honeysql 2.0 for people who may be looking for pg support
how do I write this?
(sql/format {:update :foo :set {:dismiss "dissmis + 1"}})
I tend to just go with hugsql for queries like this
but there might be a good way to do it in honeysql?
[:+ dissmis 1]
is the expression
user=> (sql/format {:update :foo :set {:dismiss [:+ :dissmis 1]}})
["UPDATE foo SET dismiss = dissmis + ?" 1]
@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"]
See https://github.com/seancorfield/honeysql/tree/v2#updates
I am using v1 still at work.
There's an example in the v1 readme too!
my bad then, but thanks for answering :)
You have to use (sql/call :+ :watched 1)
in V1 https://github.com/seancorfield/honeysql#updates
I see yeah, hm. I did scan the unit tests for this
(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)
thanks a lot, this helps
I still think the helpers are somewhat magic, but I guess not
They're a lot less "magic" in V2 since they're nearly all implemented with the same generic function 🙂