friemen / aggregate

Persisting complex datastructures to SQL tables.
88 stars 2 forks source link

Add support for tempids #9

Open OscarMarshall opened 7 years ago

OscarMarshall commented 7 years ago

When inserting data, I would love the ability to give entities a temporary id (could be a string, negative int, keyword, etc.--something that can't be mistaken as a real id) so that multiple instances of that tempid resolve to the same id.

For instance, the example given in the readme which inserts the project

{:name "Learning Clojure"
 :customer {:name "Big Company"}
 :tasks [{:desc "Buy a good book" :effort 1}
         {:desc "Install Java" :effort 2}
         {:desc "Configure Emacs" :effort 4}]
 :members [{:name "Daisy"}
           {:name "Mini"}]
 :manager {:name "Daisy"}}

ends up inserting Daisy twice: once as a member and once as a manager. Two entities with the ids 1 and 2, both with the name "Daisy", are inserted. Adding tempids would allow for the project

{:name "Learning Clojure"
 :customer {:name "Big Company"}
 :tasks [{:desc "Buy a good book" :effort 1}
         {:desc "Install Java" :effort 2}
         {:desc "Configure Emacs" :effort 4}]
 :members [{:id "daisy's tempid", :name "Daisy"} ; notice the id
           {:name "Mini"}]
 :manager {:id "daisy's tempid", :name "Daisy"}} ; notice the id

which would only insert Daisy once.

friemen commented 7 years ago

Sounds like a quite useful feature. I'll try to implement it next week.