Fork me on GitHub
#honeysql
<
2021-08-06
>
john-shaffer02:08:28

Added clojure-mode, syntax highlighting, and permalinks to https://www.john-shaffer.com/honeysql/

john-shaffer02:08:52

I'd like to add multiple versions in a dropdown (once it's relevant), so the permalinks will stay perma

seancorfield03:08:31

@jshaffer2112 Is this something you're planning to keep online and maintain now? Just wondering whether to add it to the docs since I think it's a great resource!

john-shaffer04:08:02

Yes, I'll keep it maintained. It'd be nice to have it in the docs

seancorfield18:08:56

I've added links to the README and the Getting Started section so it'll be part of the next release's documentation (2.0 "gold"). Thank again for this @jshaffer2112!

👍 3
john-shaffer04:08:23

I use it all the time

seancorfield05:08:32

Cool. I've made a note to remind me to add it to the docs. Thank you!

Adie07:08:25

[honeysql-postgres.helpers :as psqlh]
(defn upsert!
  [table record constraint-name where-clause]
  (-> (insert-into table)
      (values [record])
      (where* where-clause)
      (psqlh/upsert (-> (psqlh/on-conflict-constraint constraint-name)
                        (psqlh/do-update-set :id
                                             :tag)
                        ))
      sql/format)
  )
Can somebody suggest how I can make this function generic and remove the coupling with :id and :tag . I need to fetch the keys from record. Record looks like this :

Adie07:08:22

{:id "abcdef", :tag {:ab "hello" :bc "world"}}

Adie07:08:12

I tried replacing :id :tag with (keys record)

Adie07:08:16

but it didnt help

Adie07:08:02

This is the input format for psqlh/do-update-set

(defhelper do-update-set [m args]
  (assoc m :do-update-set (sqlh/collify args)))

Adie07:08:40

(keys record) => (:id :tag)

seancorfield17:08:42

@aditi.mishra That's for the nilenso library?

seancorfield17:08:15

I suspect you could do something like (assoc :do-update-set (into [] (keys record))) depending on exactly what that do-update-set helper uses as the underlying key...