SlideShare a Scribd company logo
1 of 33
Download to read offline
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

More Related Content

Recently uploaded

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 

Recently uploaded (20)

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

DataMapper In 20 min

  • 1. DataMapper i n 2 0 m i n
  • 2. Matt Aimonetti Me irc: m a t t e t t i
  • 3. Consultant Me based in San Diego, CA
  • 4. Blogs: http://merbist.com http://railsontherun.com
  • 5. DataMapper i n 2 0 m i n DM = Object Relational Mapper
  • 6. DataMapper ORM i n 2 0 m i n Databases scalar values da ta objects Object Oriented Languages
  • 7. DataMapper i n 2 0 m i n SELECT * FROM Book WHERE price > 100.00 ORDER BY title; Raw SQL statements FTL
  • 8. DataMapper i n 2 0 m i n Book.all( :price.gt => 100.00, :order => [:title.asc] ) Pure Ruby FTW
  • 9. DataMapper i n 2 0 m i n Book.find( :all, :conditions => [quot;price > ?quot;, 100.00], :order => quot;titlequot; ) ¿SQL/Ruby FAIL?
  • 10. DataMapper i n 2 0 m i n DM is MORE THAN THAT
  • 11. 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
  • 12. DataMapper i n 2 0 m i n Does what ActiveRecord does but differently
  • 13. DataMapper Data Objects i n 2 0 m i n Copyright - Merb in Action - Manning db drivers using 1 unified interface
  • 14. DataMapper Lazy loading + i n 2 0 m i n Strategic Eager Loader Procrastination becomes an ORM value
  • 15. DataMapper Lazy loading + SEL i n 2 0 m i n #first, #each, #count, #map... DM only generates a query when encountering a kicker
  • 16. 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
  • 17. 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
  • 18. 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
  • 19. DataMapper Lazy load i n 2 0 m i n DM doesn’t load all properties for each request unless required
  • 20. 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
  • 21. DataMapper Multiple Repos i n 2 0 m i n Article.copy(:default, :nightly_backup, :created.gt => 1.day.ago )
  • 22. DataMapper Multiple Repos i n 2 0 m i n Article.copy(:nightly_backup, :weekly_backup, :created.gt => 1.week.ago )
  • 23. 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
  • 24. DataMapper Adapters i n 2 0 m i n Provide an interface between your models and a data store.
  • 25. DataMapper Adapters i n 2 0 m i n imap file system salesforce API REST couchdb ferret google video - http scraper
  • 26. 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
  • 27. DataMapper Lazy Attributes i n 2 0 m i n Sales Force read-write DM adapter 200 LOC
  • 28. DataMapper Migrations i n 2 0 m i n automigrate autoupdate migration
  • 29. DataMapper Custom Types i n 2 0 m i n Load / Dump
  • 30. 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
  • 31. 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;
  • 32. 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;
  • 33. DataMapper i n 2 0 m i n Credits people who helped with this presentation: dbussink, dkubb, afrench, wycats