SlideShare una empresa de Scribd logo
1 de 26
Descargar para leer sin conexión
DataMapper
  An Introduction
Similarities

 • Associations
 • Validations
 • Migrations
Identity Map
@parent = Parent.first(:name => 'John')

@parent.children.each do |child|
 child.parent.should == @parent
end

# => true
Properties
class User
  include DataMapper::Resource

 property :name, String, :index => true,
  :nullable => false, :length => 30
 property :email, String, :nullable => false,
  :length => 255, :format => :email_address
 property :password, String, :nullable => false
 property :remarks, Text

end
Custom Types
Custom Data-types
 •   Csv

 •   Enum

 •   EpochTime

 •   FilePath

 •   Flag

 •   IPAddress

 •   URI

 •   Yaml

 •   Regex
Lazy Loading
class Post
  ..
  property :body, Text, :lazy => false
  property :summary, Text, :lazy => [:show]
  property :subtitle, String, :lazy => [:show]
  property :views, Integer, :lazy => [:count]
  ..
end
Multiple Repositories
class Page
  include DataMapper::Resource

 property :id, Serial
 property :name, String

 repository(:legacy) do
  property :name, String, :field => 'title'
 end
end

Page.all(:repository => :legacy)
Auto Validations
property :email, String, :length => 255, :nullable => false

# => email varchar(255) not null (create table SQL)
# => validate_present :email
# => validate_length :email, :max => 255
Migrations
• Auto Migrate
• Auto Upgrade
• Migration
Finding Records
exhibitions = Exhibition.all(:run_time.gt => 2, :run_time.lt => 5)

# => SQL conditions: 'run_time > 1 AND run_time < 5'
class Zoo
  # all the keys and property setup here
  def self.open
   all(:open => true)
  end

 def self.big
  all(:animal_count.gte => 1000)
 end
end

big_open_zoos = Zoo.big.open
big_open_zoos = Zoo.all(:open => true).all(:animal_count.gte =>
                            1000)
big_open_zoos = Zoo.all(:open =>
 true).all(:animal_count.gte => 1000)
# => This line of code generate zero sql

big_open_zoos.each do |zoo|
 puts zoo.name
end
# => This generates one sql.
Kicker methods
  • #each
  • #first
  • #last
  • #count
  • #map
  • etc
Strategic Eager Loading
Query Path
Person.all(quot;addresses.street.likequot; => '%marina%')

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 '%marina%')
ORDER BY quot;peoplequot;.quot;idquot;
Questions?

Más contenido relacionado

Destacado (6)

Action And Linking Verbs
Action And Linking VerbsAction And Linking Verbs
Action And Linking Verbs
 
Trabajo De Laboratorio
Trabajo De LaboratorioTrabajo De Laboratorio
Trabajo De Laboratorio
 
Conclusies, Inge Schoups (FelixArchief/eDAVID), voorzitter van het Platform D...
Conclusies, Inge Schoups (FelixArchief/eDAVID), voorzitter van het Platform D...Conclusies, Inge Schoups (FelixArchief/eDAVID), voorzitter van het Platform D...
Conclusies, Inge Schoups (FelixArchief/eDAVID), voorzitter van het Platform D...
 
Sentença Serinhaem
Sentença SerinhaemSentença Serinhaem
Sentença Serinhaem
 
Escape!
Escape!Escape!
Escape!
 
20081126 Web2 Crash Course Kristof
20081126 Web2 Crash Course Kristof20081126 Web2 Crash Course Kristof
20081126 Web2 Crash Course Kristof
 

Similar a Dm Intro

Building Web Interface On Rails
Building Web Interface On RailsBuilding Web Interface On Rails
Building Web Interface On Rails
Wen-Tien Chang
 
Java.script
Java.scriptJava.script
Java.script
g Nama
 
Rails 3 And The Real Secret To High Productivity Presentation
Rails 3 And The Real Secret To High Productivity PresentationRails 3 And The Real Secret To High Productivity Presentation
Rails 3 And The Real Secret To High Productivity Presentation
railsconf
 
Introduction à CoffeeScript pour ParisRB
Introduction à CoffeeScript pour ParisRB Introduction à CoffeeScript pour ParisRB
Introduction à CoffeeScript pour ParisRB
jhchabran
 

Similar a Dm Intro (20)

Merb jQuery
Merb jQueryMerb jQuery
Merb jQuery
 
Building Web Interface On Rails
Building Web Interface On RailsBuilding Web Interface On Rails
Building Web Interface On Rails
 
WTF Oriented Programming, com Fabio Akita
WTF Oriented Programming, com Fabio AkitaWTF Oriented Programming, com Fabio Akita
WTF Oriented Programming, com Fabio Akita
 
MySQLConf2009: Taking ActiveRecord to the Next Level
MySQLConf2009: Taking ActiveRecord to the Next LevelMySQLConf2009: Taking ActiveRecord to the Next Level
MySQLConf2009: Taking ActiveRecord to the Next Level
 
Real life-coffeescript
Real life-coffeescriptReal life-coffeescript
Real life-coffeescript
 
Little Big Ruby
Little Big RubyLittle Big Ruby
Little Big Ruby
 
Scala, XML and GAE
Scala, XML and GAEScala, XML and GAE
Scala, XML and GAE
 
What's new in Rails 2?
What's new in Rails 2?What's new in Rails 2?
What's new in Rails 2?
 
Scala introduction
Scala introductionScala introduction
Scala introduction
 
Java.script
Java.scriptJava.script
Java.script
 
Html
HtmlHtml
Html
 
Page Caching Resurrected
Page Caching ResurrectedPage Caching Resurrected
Page Caching Resurrected
 
Rails 3 And The Real Secret To High Productivity Presentation
Rails 3 And The Real Secret To High Productivity PresentationRails 3 And The Real Secret To High Productivity Presentation
Rails 3 And The Real Secret To High Productivity Presentation
 
Ten modules I haven't yet talked about
Ten modules I haven't yet talked aboutTen modules I haven't yet talked about
Ten modules I haven't yet talked about
 
Acceptance Testing with Webrat
Acceptance Testing with WebratAcceptance Testing with Webrat
Acceptance Testing with Webrat
 
Rugalytics | Ruby Manor Nov 2008
Rugalytics | Ruby Manor Nov 2008Rugalytics | Ruby Manor Nov 2008
Rugalytics | Ruby Manor Nov 2008
 
Framework
FrameworkFramework
Framework
 
CoffeeScript - A Rubyist's Love Affair
CoffeeScript - A Rubyist's Love AffairCoffeeScript - A Rubyist's Love Affair
CoffeeScript - A Rubyist's Love Affair
 
Jicc teaching rails
Jicc teaching railsJicc teaching rails
Jicc teaching rails
 
Introduction à CoffeeScript pour ParisRB
Introduction à CoffeeScript pour ParisRB Introduction à CoffeeScript pour ParisRB
Introduction à CoffeeScript pour ParisRB
 

Último

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
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
Enterprise Knowledge
 

Último (20)

2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
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
 
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
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
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
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
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
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 

Dm Intro