Uploaded on

An introduction to DataMapper

An introduction to DataMapper

More in: Technology , Education
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
449
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
9
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. DataMapper An Introduction
  • 2. Similarities • Associations • Validations • Migrations
  • 3. Identity Map
  • 4. @parent = Parent.first(:name => 'John') @parent.children.each do |child| child.parent.should == @parent end # => true
  • 5. Properties
  • 6. 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
  • 7. Custom Types
  • 8. Custom Data-types • Csv • Enum • EpochTime • FilePath • Flag • IPAddress • URI • Yaml • Regex
  • 9. Lazy Loading
  • 10. class Post .. property :body, Text, :lazy => false property :summary, Text, :lazy => [:show] property :subtitle, String, :lazy => [:show] property :views, Integer, :lazy => [:count] .. end
  • 11. Multiple Repositories
  • 12. 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)
  • 13. Auto Validations
  • 14. property :email, String, :length => 255, :nullable => false # => email varchar(255) not null (create table SQL) # => validate_present :email # => validate_length :email, :max => 255
  • 15. Migrations
  • 16. • Auto Migrate • Auto Upgrade • Migration
  • 17. Finding Records
  • 18. exhibitions = Exhibition.all(:run_time.gt => 2, :run_time.lt => 5) # => SQL conditions: 'run_time > 1 AND run_time < 5'
  • 19. 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
  • 20. big_open_zoos = Zoo.all(:open => true).all(:animal_count.gte => 1000)
  • 21. 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.
  • 22. Kicker methods • #each • #first • #last • #count • #map • etc
  • 23. Strategic Eager Loading
  • 24. Query Path
  • 25. 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;
  • 26. Questions?