korma / Korma

Tasty SQL for Clojure.
http://sqlkorma.com
1.47k stars 222 forks source link

Make order of values for insert queries not matter #332

Closed tie-rack closed 8 years ago

tie-rack commented 8 years ago

So that the two following queries insert the same data:

(insert users
        (values [{:first "icarus"}
                 {:first "chris" :last "granger"}]))

(insert users
        (values [{:first "chris" :last "granger"}
                 {:first "icarus"}]))

Currently, the keys from the first map in values are used to determine the columns for an insert, which can lead to some values not being fully inserted.

I ran into this problem with a process that produced maps that may not include all the keys for a table. Finding out that the database was missing data was not fun.

immoh commented 8 years ago

Wouldn't (distinct (mapcat keys (:values query))) be simpler?

tie-rack commented 8 years ago

@immoh Good call, updated.

immoh commented 8 years ago

Could you squash the commits and I'll merge this? Thanks.

tie-rack commented 8 years ago

Squashed. Thank you!