I gave a talk about the two patterns Active Record and Data Mapper and compared them with special regards to using them with NoSQL Databases. The code examples are in Ruby, but it is not Ruby specific ;)
by solnic) require "active_record" class ClassWithActiveRecord < ActiveRecord::Base; end (ClassWithActiveRecord.methods - Object.methods).count # => 391 # It consists of 77 modules
Define a model class User include DataMapper::Model attribute :id, Integer attribute :name, String attribute :age, Integer end # Define a mapper DataMapper.generate_mapper_for(User) do key :id map :name, :to => :username end # Search for data DataMapper[User].all DataMapper[User].order(:age) DataMapper[User].find(age: 23)
another model • This can be used for has_many etc. • … but it is also handy in a Document Store • The model doesn‘t need to care, only the mapper has to handle the difference
and their modifications • Handles how updates are made • Instead of the invokin explicit save methods, tell the unit of work to commit • Works reat with Data Mapper • Works reat with batch requests Unit of Work
fit in a lot of cases • It has better support for denormalization • DataMapper and NoSQL make the database become a detail, simplifyin tests • With a Workin Set you can take full advanta e of batch requests