Dm Intro
Upcoming SlideShare
Loading in...5
×
 

Dm Intro

on

  • 903 views

An introduction to DataMapper

An introduction to DataMapper

Statistics

Views

Total Views
903
Views on SlideShare
903
Embed Views
0

Actions

Likes
0
Downloads
9
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

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

Dm Intro Dm Intro Presentation Transcript

  • DataMapper An Introduction
  • Similarities • Associations • Validations • Migrations
  • Identity Map View slide
  • @parent = Parent.first(:name => 'John') @parent.children.each do |child| child.parent.should == @parent end # => true View slide
  • 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?