This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-11-10
Channels
- # asami (41)
- # babashka (24)
- # beginners (48)
- # calva (41)
- # cider (10)
- # clj-commons (20)
- # clj-kondo (2)
- # cljdoc (8)
- # clojure (131)
- # clojure-australia (4)
- # clojure-europe (17)
- # clojure-hungary (2)
- # clojure-india (2)
- # clojure-nl (3)
- # clojure-uk (1)
- # clojurescript (12)
- # community-development (6)
- # core-logic (4)
- # cursive (11)
- # datomic (22)
- # emacs (25)
- # events (1)
- # exercism (2)
- # fulcro (30)
- # helix (5)
- # honeysql (6)
- # hugsql (3)
- # integrant (12)
- # introduce-yourself (4)
- # lsp (5)
- # malli (5)
- # nextjournal (31)
- # off-topic (4)
- # pedestal (3)
- # portal (51)
- # reitit (33)
- # remote-jobs (1)
- # shadow-cljs (12)
- # sql (10)
- # vim (7)
- # xtdb (37)
hey, there, quite new to honeysql (but not SQL). Here’s two examples that are supposedly doing the same thing, however, only the second one seems to create the right SQL:
(let [data '({:installer-id "bubu"
:states (sql-types/array ["CA" "DC"])
:improvement-type-id #uuid"7efc8a9e-a317-424f-a775-ba4bf6a5bf94"
})]
(-> (hsql/insert-into :installer-improvement-types)
(hsql/values data)
(sql/format :pretty true)))
=>
["INSERT INTO installer_improvement_types (installer_id, states, improvement_type_id) VALUES (?, array ? DC, ?)"
"bubu"
"CA"
#uuid"7efc8a9e-a317-424f-a775-ba4bf6a5bf94"]
(-> (hsql/insert-into :installer-improvement-types)
(hsql/columns :installer-id :states :improvement-type-id)
(hsql/values [["bubu" (sql-types/array ["CA" "DC"]) #uuid"7efc8a9e-a317-424f-a775-ba4bf6a5bf94"]])
(sql/format :pretty true))
=>
["INSERT INTO installer_improvement_types (installer_id, states, improvement_type_id) VALUES (?, ARRAY[?, ?], ?)"
"bubu"
"CA"
"DC"
#uuid"7efc8a9e-a317-424f-a775-ba4bf6a5bf94"]
In the first form you've quoted the whole expression so sql-types
is not evaluated.
(let [data [{:installer-id "bubu"
:states (sql-types/array ["CA" "DC"])
:improvement-type-id #uuid"7efc8a9e-a317-424f-a775-ba4bf6a5bf94"
}]]
(-> (hsql/insert-into :installer-improvement-types)
(hsql/values data)
(sql/format :pretty true)))
That should do what you want @beders(no quote, use a vector instead of a list)