Fork me on GitHub
#datascript
<
2017-04-18
>
dmitriid12:04:11

Hi all. A quick and stupid question 🙂 I’m playing with an old API for an “events” endpoint, and this is the data I get:

{:description "", :musicIdArray [], :venueId 1, :music [], :startTime "2017-03-01T22:00:00+02:00", …}
In order to dump it into Datascript I need to convert it to :event/description, :event/musicIdArray etc. What would be the best way to do it?

dmitriid14:04:56

hmmm… or do a transact! and doseq inside the transaction and transform the keys with (keyword "events" (name key)))? … 🙂

dmitriid14:04:11

:thinking_face:

dmitriid17:04:46

Well, a solution-ish is (reduce #(assoc %1 (to-prefixed-keyword :event %2) (%2 event)) {} (keys event)))) where

(defn to-prefixed-keyword [prefix key]
  (keyword (name prefix) (name key)))
I’ll leave it at that for now 🙂