This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-02-08
Channels
- # aleph (7)
- # announcements (12)
- # babashka (19)
- # beginners (4)
- # calva (29)
- # cider (20)
- # clj-kondo (20)
- # clojure (66)
- # clojure-austin (4)
- # clojure-europe (11)
- # clojure-nl (1)
- # clojure-norway (42)
- # clojure-uk (4)
- # clojuredesign-podcast (9)
- # conjure (1)
- # cursive (5)
- # datomic (42)
- # etaoin (4)
- # events (10)
- # garden (8)
- # graphql (1)
- # holy-lambda (7)
- # honeysql (3)
- # hyperfiddle (5)
- # missionary (11)
- # music (1)
- # off-topic (12)
- # practicalli (2)
- # re-frame (2)
- # reitit (6)
- # releases (2)
- # vim (2)
- # web-security (1)
- # xtdb (3)
I want to generate SQL like insert into foo (a, b) values (?, ? format json)
, and then provide a string as the 2nd parameter. Can I do this using honeysql? I tried to do this by registering a function.
(hsql/register-fn! :h2-json
(fn [_ arg]
["? format json" arg]))
and then using this in an expression in a value. e.g.
{:insert-into [:collection.event-v1],
:columns [:event-id :type :game-id :attributes],
:values
[["5d600f99-ac53-5c44-b9e5-a0cd54a5a0b7"
"starting_xi"
1147541
[:h2-json
"{\"video_timestamp\":0,\"game_id\":1147541,\"team_directions\":{\"1277\":\"right_to_left\",\"1285\":\"left_to_right\"},\"formation\":\"4-2-3-1\",\"index\":1,\"name\":\"starting_xi\",\"event_id\":\"5d600f99-ac53-5c44-b9e5-a0cd54a5a0b7\",\"team_id\":1285,\"period\":1,\"lineup\":{\"rw\":1013520,\"gk\":81405,\"rdm\":1012881,\"ldm\":134650,\"rb\":139914,\"cam\":1012550,\"lb\":75078,\"lw\":1018595,\"cf\":86937,\"rcb\":83675,\"lcb\":87310},\"arqam_event_id\":305226079,\"related_events\":[],\"opposition_team_id\":1277}"]]]}
Unfortunately, when this is formatted, the [:h2-json
expression comes in a list
["INSERT INTO collection.event_v1 (event_id, type, game_id, attributes) VALUES (?, ?, ?, ? format json)"
"5d600f99-ac53-5c44-b9e5-a0cd54a5a0b7"
"starting_xi"
1147541
("{\"video_timestamp\":0,\"game_id\":1147541,\"team_directions\":{\"1277\":\"right_to_left\",\"1285\":\"left_to_right\"},\"formation\":\"4-2-3-1\",\"index\":1,\"name\":\"starting_xi\",\"event_id\":\"5d600f99-ac53-5c44-b9e5-a0cd54a5a0b7\",\"team_id\":1285,\"period\":1,\"lineup\":{\"rw\":1013520,\"gk\":81405,\"rdm\":1012881,\"ldm\":134650,\"rb\":139914,\"cam\":1012550,\"lb\":75078,\"lw\":1018595,\"cf\":86937,\"rcb\":83675,\"lcb\":87310},\"arqam_event_id\":305226079,\"related_events\":[],\"opposition_team_id\":1277}")]