Reputation: 784
New to Clojure.
I am trying to build up a data structure programmatically for insertion into a database. I actually have something that works just fine, but it does an insert for each record, and I'd like to generate the whole record, and then insert the whole thing at once with one insert.
Here is what I have working so far:
(doseq [record-data1 [:one :two :three]
(doseq [record-data2 [1 2 3]]
(insert {record-data1 record-data2})
Any suggestions on how to generate the entire bulk structure first before insert? Have tried variations on map, walk, etc. but haven't been able to come up with anything yet.
Thanks.
Upvotes: 0
Views: 129
Reputation: 18429
I'm not sure I understand what you mean by "entire bulk structure". You can't put the cross-product of record-data1 and record-data2 in the same dictionary. Maybe you're looking for this:
user=> (for [record-data1 [:a :b :c] record-data2 [1 2 3]] {record-data1 record-data2})
({:a 1} {:a 2} {:a 3} {:b 1} {:b 2} {:b 3} {:c 1} {:c 2} {:c 3})
Upvotes: 1