Idea
Create unit of work implementation with identity map and smart bulk insert sessions. It will allow us to write clean, idiomatic code and don't care about performance.
Dml.session do
company = Company.new(name: 'Simpsons Corp')
%w(Marge Homer Bart Lisa).each do |name|
user = User.new(name: name, company: company)
UsersRepository.insert(user)
end
CompaniesRepository.insert(company)
end # trigger insert/update
will generate
INSERT INTO companies (name) VALUES ('Simpsons Corp'); -- id = 42
INSERT INTO users (name, company_id) VALUES ('Marge', 42), ('Homer', 42) ...
And
Dml.session do
UsersRepository.preload(user_ids) # Will retrieve all records immediately
user_ids.each do |id|
UsersRepository.fetch(id) # will fetch record from the Identity Map
end
locations.each do |location|
location.user # if preloaded will fetch record from Identity Map
end
end
Roadmap
Relation mapper
Session
Entity
Repository
Things to decide
- How to comfortably and efficiently preload entity 1..n associated entities
- How to comfortably and efficiently preload collection associated entities (all and exact)
- How to manage self-references
Idea
Create unit of work implementation with identity map and smart bulk insert sessions. It will allow us to write clean, idiomatic code and don't care about performance.
will generate
And
Roadmap
Relation mapper
Session
Entity
Repository
#{insert/update}_immediatemethods (directly call provider methods and update IM)#preloadmethodThings to decide