SlideShare una empresa de Scribd logo
1 de 48
Dirkjan Bussink
   http://github.com/dbussink
          @dbussink
Why?
Declarative
class Person
  include DataMapper::Resource
  property :id, Serial
  property :name, String, :required => true
  property :age, Integer
end
Automatic
migrations
DataMapper.auto_migrate!

DataMapper.auto_upgrade!
Storage
constraints
class Person
  include DataMapper::Resource
  property :id, Serial
  property :name, String, :required => true
  property :age, Integer
end
class Person
  include DataMapper::Resource
  property :id, Serial
  property :name, String, :required => true
  property :age, Integer
end



CREATE TABLE "people" ("id" SERIAL NOT NULL,
                       "name" VARCHAR(50) NOT NULL,
                       "age" INTEGER, PRIMARY KEY("id"))
class Person
  include DataMapper::Resource
  property :id, Serial
  property :name, String, :required => true
  property :age, Integer

  has n, :addresses, :constraint => :destroy!
end
class Person
  include DataMapper::Resource
  property :id, Serial
  property :name, String, :required => true
  property :age, Integer

  has n, :addresses, :constraint => :destroy!
end

ALTER TABLE addresses
ADD CONSTRAINT addresses_person_id_fk
FOREIGN KEY (person_id)
REFERENCES people ON DELETE CASCADE ON UPDATE CASCADE
Automatic
validations
class Person
  include DataMapper::Resource
  property :id, Serial
  property :name, String, :required => true
  property :age, Integer
end
class Person
      include DataMapper::Resource
      property :id, Serial
      property :name, String, :required => true
      property :age, Integer
    end

person = Person.create
person.errors => #<DataMapper::Validations::ValidationErrors:0x101d217a0
                   @errors={:name=>["Name must not be blank"]},
                   @resource=#<Person @id=nil @name=nil @age=nil>>
http://www.flickr.com/photos/jon_truran
Convenience
"that just pisses me off"
Lazyness
people = Person.all
~ Query log empty...
people = Person.all
     ~ Query log empty...


p people
~ SELECT "id", "name" FROM people
:each
people = Person.all
people.each do |person|
  p person.addresses
end
people = Person.all
people.each do |person|
  p person.addresses
end
SELECT "id", "name" FROM people;
SELECT "id", "street" FROM addresses WHERE ("person_id" IN (1,2,3))
Complex
 queries
Person.all(:addresses => {:street.like => "%street%"})
Person.all(:addresses => {:street.like => "%street%"})



    SELECT   "people"."id", "people"."name", "people"."age" FROM "people"
INNER JOIN   "addresses" ON "people"."id" = "addresses"."person_id"
     WHERE   "addresses"."street" LIKE '%street%'
  GROUP BY   "people"."id", "people"."name", "people"."age"
  ORDER BY   "people"."id"
class Person
  include DataMapper::Resource

  ...

  def self.named_like_me
    all(:name.like => "%me%")
  end

end
class Person
  include DataMapper::Resource

  ...

  def self.named_like_me
    all(:name.like => "%me%")
  end

end

Person.named_like_me.all(:age.gt => 27)

~ SELECT "id", "name", "age" FROM "people"
   WHERE ("name" LIKE '%me%' AND "age" > 27) ORDER BY "id"
Person.all(:name.like => '%me%').addresses.all(:street.not => nil)
Person.all(:name.like => '%me%').addresses.all(:street.not => nil)


  SELECT "id", "street", "person_id" FROM "addresses"
   WHERE (
           "person_id" IN (SELECT "id" FROM "people" WHERE "name" LIKE '%me%')
           AND "street" IS NOT NULL
   ) ORDER BY "id"
Person.all - Person.all(:name => 'Dan Kubb')
Person.all - Person.all(:name => 'Dan Kubb')


      SELECT * FROM people WHERE NOT(name = 'Dan Kubb')
Not SQL centric
DataMapper.setup(:default, "postgres://postgres@localhost/dm")
DataMapper.setup(:docs, "mongo://user@localhost/dm")
class Post
  include DataMapper::Resource
  has n, :audits
end

class Audit
  include DataMapper::Resource
  def self.default_repository_name
    :log
  end
end
Custom
adapters
module DataMapper
  module Adapters

    class MyStorageAdapter < AbstractAdapter

      def create(resources)
      end

      def read(query)
      end

      def update(attributes, collection)
      end

      def delete(collection)
      end

    end
  end
end
Future
class Address
  include DataMapper::EmbeddedValue

  property :street,       String
end

class Person
  include DataMapper::Resource

  property :id,       Serial
  property :name,     String
  has n, :addresses
end
drops into2008
Back to   Rails
      1.0
1.8 / 1.9
(on Windows too)
Dan Kubb

Martin Gamsjaeger
http://datamapper.org/
      http://github.com/datamapper
              @datamapper
http://groups.google.com/group/datamapper
      irc://irc.freenode.net/#datamapper

Más contenido relacionado

La actualidad más candente

Kick start with j query
Kick start with j queryKick start with j query
Kick start with j query
Md. Ziaul Haq
 
Using jQuery to Extend CSS
Using jQuery to Extend CSSUsing jQuery to Extend CSS
Using jQuery to Extend CSS
Chris Coyier
 
Юрий Буянов «Squeryl — ORM с человеческим лицом»
Юрий Буянов «Squeryl — ORM с человеческим лицом»Юрий Буянов «Squeryl — ORM с человеческим лицом»
Юрий Буянов «Squeryl — ORM с человеческим лицом»
e-Legion
 
Leveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHPLeveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHP
Jeremy Kendall
 

La actualidad más candente (20)

Kick start with j query
Kick start with j queryKick start with j query
Kick start with j query
 
PhoneGap: Local Storage
PhoneGap: Local StoragePhoneGap: Local Storage
PhoneGap: Local Storage
 
The jQuery Divide
The jQuery DivideThe jQuery Divide
The jQuery Divide
 
Transparent Object Persistence with FLOW3
Transparent Object Persistence with FLOW3Transparent Object Persistence with FLOW3
Transparent Object Persistence with FLOW3
 
jQuery Fundamentals
jQuery FundamentalsjQuery Fundamentals
jQuery Fundamentals
 
An introduction to jQuery
An introduction to jQueryAn introduction to jQuery
An introduction to jQuery
 
Self join in active record association
Self join in active record associationSelf join in active record association
Self join in active record association
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
jQuery Essentials
jQuery EssentialsjQuery Essentials
jQuery Essentials
 
Using jQuery to Extend CSS
Using jQuery to Extend CSSUsing jQuery to Extend CSS
Using jQuery to Extend CSS
 
Play, Slick, play2-authの間で討死
Play, Slick, play2-authの間で討死Play, Slick, play2-authの間で討死
Play, Slick, play2-authの間で討死
 
Юрий Буянов «Squeryl — ORM с человеческим лицом»
Юрий Буянов «Squeryl — ORM с человеческим лицом»Юрий Буянов «Squeryl — ORM с человеческим лицом»
Юрий Буянов «Squeryl — ORM с человеческим лицом»
 
Php 102: Out with the Bad, In with the Good
Php 102: Out with the Bad, In with the GoodPhp 102: Out with the Bad, In with the Good
Php 102: Out with the Bad, In with the Good
 
jQuery UI Widgets, Drag and Drop, Drupal 7 Javascript
jQuery UI Widgets, Drag and Drop, Drupal 7 JavascriptjQuery UI Widgets, Drag and Drop, Drupal 7 Javascript
jQuery UI Widgets, Drag and Drop, Drupal 7 Javascript
 
Learning jQuery in 30 minutes
Learning jQuery in 30 minutesLearning jQuery in 30 minutes
Learning jQuery in 30 minutes
 
Prototype & jQuery
Prototype & jQueryPrototype & jQuery
Prototype & jQuery
 
Leveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHPLeveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHP
 
Leveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHPLeveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHP
 
Jquery-overview
Jquery-overviewJquery-overview
Jquery-overview
 
Country State City Dropdown in PHP
Country State City Dropdown in PHPCountry State City Dropdown in PHP
Country State City Dropdown in PHP
 

Similar a Datamapper @ Railsconf2010

The Ruby/mongoDB ecosystem
The Ruby/mongoDB ecosystemThe Ruby/mongoDB ecosystem
The Ruby/mongoDB ecosystem
Harold Giménez
 
NoSQL を Ruby で実践するための n 個の方法
NoSQL を Ruby で実践するための n 個の方法NoSQL を Ruby で実践するための n 個の方法
NoSQL を Ruby で実践するための n 個の方法
Tomohiro Nishimura
 
Desarrollando aplicaciones web en minutos
Desarrollando aplicaciones web en minutosDesarrollando aplicaciones web en minutos
Desarrollando aplicaciones web en minutos
Edgar Suarez
 
Ex[1].3 php db connectivity
Ex[1].3 php db connectivityEx[1].3 php db connectivity
Ex[1].3 php db connectivity
Mouli Chandira
 

Similar a Datamapper @ Railsconf2010 (20)

The Ruby/mongoDB ecosystem
The Ruby/mongoDB ecosystemThe Ruby/mongoDB ecosystem
The Ruby/mongoDB ecosystem
 
NoSQL を Ruby で実践するための n 個の方法
NoSQL を Ruby で実践するための n 個の方法NoSQL を Ruby で実践するための n 個の方法
NoSQL を Ruby で実践するための n 個の方法
 
Automatically Spotting Cross-language Relations
Automatically Spotting Cross-language RelationsAutomatically Spotting Cross-language Relations
Automatically Spotting Cross-language Relations
 
Data access 2.0? Please welcome: Spring Data!
Data access 2.0? Please welcome: Spring Data!Data access 2.0? Please welcome: Spring Data!
Data access 2.0? Please welcome: Spring Data!
 
Persisting Data on SQLite using Room
Persisting Data on SQLite using RoomPersisting Data on SQLite using Room
Persisting Data on SQLite using Room
 
Drupal Mobile
Drupal MobileDrupal Mobile
Drupal Mobile
 
The State of Lithium
The State of LithiumThe State of Lithium
The State of Lithium
 
Elastic tire demo
Elastic tire demoElastic tire demo
Elastic tire demo
 
Couchdb
CouchdbCouchdb
Couchdb
 
Ruby is Awesome
Ruby is AwesomeRuby is Awesome
Ruby is Awesome
 
DataMapper
DataMapperDataMapper
DataMapper
 
An introduction into Spring Data
An introduction into Spring DataAn introduction into Spring Data
An introduction into Spring Data
 
3 database-jdbc(1)
3 database-jdbc(1)3 database-jdbc(1)
3 database-jdbc(1)
 
Desarrollando aplicaciones web en minutos
Desarrollando aplicaciones web en minutosDesarrollando aplicaciones web en minutos
Desarrollando aplicaciones web en minutos
 
Mobile Database Persistence
Mobile Database PersistenceMobile Database Persistence
Mobile Database Persistence
 
Ex[1].3 php db connectivity
Ex[1].3 php db connectivityEx[1].3 php db connectivity
Ex[1].3 php db connectivity
 
MongoDB and RDBMS
MongoDB and RDBMSMongoDB and RDBMS
MongoDB and RDBMS
 
DevNation'15 - Using Lambda Expressions to Query a Datastore
DevNation'15 - Using Lambda Expressions to Query a DatastoreDevNation'15 - Using Lambda Expressions to Query a Datastore
DevNation'15 - Using Lambda Expressions to Query a Datastore
 
Using web2py's DAL in other projects or frameworks
Using web2py's DAL in other projects or frameworksUsing web2py's DAL in other projects or frameworks
Using web2py's DAL in other projects or frameworks
 
SFScon17 - Patrick Puecher: "Exploring data with Elasticsearch and Kibana"
SFScon17 - Patrick Puecher: "Exploring data with Elasticsearch and Kibana"SFScon17 - Patrick Puecher: "Exploring data with Elasticsearch and Kibana"
SFScon17 - Patrick Puecher: "Exploring data with Elasticsearch and Kibana"
 

Último

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
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Último (20)

Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
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
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
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
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
[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
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
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
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
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
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 

Datamapper @ Railsconf2010

Notas del editor