DataMapper In 20 min
Upcoming SlideShare
Loading in...5
×
 

DataMapper In 20 min

on

  • 23,497 views

Overview of DataMapper and the differences between DM and other Ruby ORMs.

Overview of DataMapper and the differences between DM and other Ruby ORMs.

Presentation given by Matt Aimonetti during MerbCamp 2008 in San Diego, CA.

Statistics

Views

Total Views
23,497
Views on SlideShare
23,054
Embed Views
443

Actions

Likes
20
Downloads
221
Comments
2

21 Embeds 443

http://www.slideshare.net 131
http://rubyrailsandwindows.blogspot.com 98
http://merbist.com 69
http://coderwall.com 47
http://www.merboverheard.com 45
http://merboverheard.com 13
http://rubyrailsandwindows.blogspot.in 5
http://rubyrailsandwindows.blogspot.com.au 5
http://blaze.apphb.com 5
http://rubyrailsandwindows.blogspot.com.br 5
http://www.slideee.com 4
http://www.linkedin.com 4
http://rubyrailsandwindows.blogspot.de 3
https://twitter.com 2
http://duckduckgo.com 1
http://rubyrailsandwindows.blogspot.se 1
http://rubyrailsandwindows.blogspot.co.nz 1
http://rubyrailsandwindows.blogspot.it 1
http://www.e-presentations.us 1
http://rubyrailsandwindows.blogspot.com.es 1
http://rubyrailsandwindows.blogspot.fr 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

CC Attribution-NonCommercial LicenseCC Attribution-NonCommercial License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel

12 of 2

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    DataMapper In 20 min DataMapper In 20 min Presentation Transcript

    • DataMapper i n 2 0 m i n
    • Matt Aimonetti Me irc: m a t t e t t i
    • Consultant Me based in San Diego, CA
    • Blogs: http://merbist.com http://railsontherun.com
    • DataMapper i n 2 0 m i n DM = Object Relational Mapper
    • DataMapper ORM i n 2 0 m i n Databases scalar values da ta objects Object Oriented Languages
    • DataMapper i n 2 0 m i n SELECT * FROM Book WHERE price > 100.00 ORDER BY title; Raw SQL statements FTL
    • DataMapper i n 2 0 m i n Book.all( :price.gt => 100.00, :order => [:title.asc] ) Pure Ruby FTW
    • DataMapper i n 2 0 m i n Book.find( :all, :conditions => [quot;price > ?quot;, 100.00], :order => quot;titlequot; ) ¿SQL/Ruby FAIL?
    • DataMapper i n 2 0 m i n DM is MORE THAN THAT
    • DataMapper identity map i n 2 0 m i n @parent = Parent.find_by_name(quot;Bobquot;) @parent.children.each do |child| @parent.object_id.should == child.parent.object_id end FAILS with ActiveRecord PASSES with DataMapper
    • DataMapper i n 2 0 m i n Does what ActiveRecord does but differently
    • DataMapper Data Objects i n 2 0 m i n Copyright - Merb in Action - Manning db drivers using 1 unified interface
    • DataMapper Lazy loading + i n 2 0 m i n Strategic Eager Loader Procrastination becomes an ORM value
    • DataMapper Lazy loading + SEL i n 2 0 m i n #first, #each, #count, #map... DM only generates a query when encountering a kicker
    • DataMapper Lazy loading + SEL i n 2 0 m i n zoos = Zoo.all zoos.each do |zoo| zoo.exhibits.map{|e| e.name} end
    • DataMapper Lazy loading + SEL i n 2 0 m i n SELECT * FROM quot;zoosquot; SELECT * FROM quot;exhibitsquot; WHERE (quot;exhibitsquot;.zoo_id = 1) SELECT * FROM quot;exhibitsquot; WHERE (quot;exhibitsquot;.zoo_id = 2) SELECT * FROM quot;exhibitsquot; WHERE (quot;exhibitsquot;.zoo_id = 3) 4 requests ActiveRecord
    • DataMapper Lazy loading + SEL i n 2 0 m i n SELECT quot;idquot;, quot;namequot; FROM quot;zoosquot; ORDER BY quot;idquot; SELECT quot;idquot;, quot;namequot;, quot;zoo_idquot; FROM quot;exhibitsquot; WHERE (quot;zoo_idquot; IN (1, 3, 2)) ORDER BY quot;idquot; 2 requests DataMapper
    • DataMapper Lazy load i n 2 0 m i n DM doesn’t load all properties for each request unless required
    • DataMapper Multiple Repos i n 2 0 m i n production: adapter: mysql encoding: utf8 database: production-app username: root database.yml password: top-s3ckit host: localhost repositories: nightly_backup: adapter: sqlite3 database: shared/nightly.db weekly_backup: adapter: sqlite3 database: shared/weekly.db
    • DataMapper Multiple Repos i n 2 0 m i n Article.copy(:default, :nightly_backup, :created.gt => 1.day.ago )
    • DataMapper Multiple Repos i n 2 0 m i n Article.copy(:nightly_backup, :weekly_backup, :created.gt => 1.week.ago )
    • DataMapper Legacy Data i n 2 0 m i n class Page include DataMapper::Resource property :id, Serial property :name, String repository(:legacy) do property :name, String, :field => quot;titlequot; end
    • DataMapper Adapters i n 2 0 m i n Provide an interface between your models and a data store.
    • DataMapper Adapters i n 2 0 m i n imap file system salesforce API REST couchdb ferret google video - http scraper
    • DataMapper Lazy Attributes i n 2 0 m i n google video - http scraper DM adapter 80 LOC only required to implement - a read method - handling query conditions
    • DataMapper Lazy Attributes i n 2 0 m i n Sales Force read-write DM adapter 200 LOC
    • DataMapper Migrations i n 2 0 m i n automigrate autoupdate migration
    • DataMapper Custom Types i n 2 0 m i n Load / Dump
    • DataMapper Plugins i n 2 0 m i n modular structure migration, validation, model factory, state machine, constraints, lists, tagging... DM facilitates extensions by offering nice hooks
    • DataMapper Query::Path i n 2 0 m i n Find all people with an address that has street in the street name Person.all(Person.addresses.street.like => quot;%street%quot; ) SELECT quot;peoplequot;.quot;idquot;, quot;peoplequot;.quot;namequot; FROM quot;peoplequot; INNER JOIN quot;addressesquot; ON (quot;peoplequot;.quot;idquot; = quot;addressesquot;.quot;person_idquot;) WHERE (quot;addressesquot;.quot;streetquot; LIKE '%street%') ORDER BY quot;peoplequot;.quot;idquot;
    • DataMapper Query::Path i n 2 0 m i n Find all people with an address that has street in the street name Person.all(quot;addresses.street.likequot; => quot;%street%quot; ) SELECT quot;peoplequot;.quot;idquot;, quot;peoplequot;.quot;namequot; FROM quot;peoplequot; INNER JOIN quot;addressesquot; ON (quot;peoplequot;.quot;idquot; = quot;addressesquot;.quot;person_idquot;) WHERE (quot;addressesquot;.quot;streetquot; LIKE '%street%') ORDER BY quot;peoplequot;.quot;idquot;
    • DataMapper i n 2 0 m i n Credits people who helped with this presentation: dbussink, dkubb, afrench, wycats