Fork me on GitHub
#honeysql
<
2021-03-11
>
murtaza14:03:24

👋 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.104https://github.com/nilenso/honeysql-postgres/releases/tag/0.4.112https://github.com/nilenso/honeysql-postgres/blob/master/CHANGELOG.md

murtaza15:03:29

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

borkdude17:03:46

how do I write this?

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

borkdude17:03:06

I tend to just go with hugsql for queries like this

borkdude17:03:17

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

seancorfield17:03:40

[:+ dissmis 1] is the expression

seancorfield17:03:12

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

seancorfield17:03:09

@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"]

borkdude17:03:41

I am using v1 still at work.

seancorfield17:03:52

There's an example in the v1 readme too!

borkdude17:03:20

my bad then, but thanks for answering :)

seancorfield17:03:25

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

borkdude17:03:50

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

seancorfield17:03:35

(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)

borkdude17:03:25

thanks a lot, this helps

borkdude17:03:42

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

seancorfield17:03:21

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