Dirkjan Bussink
   http://github.com/dbussink
          @dbussink
Why?
Declarative
class Person
  include DataMapper::Resource
  property :id, Serial
  property :name, String, :required => true
  property ...
Automatic
migrations
DataMapper.auto_migrate!

DataMapper.auto_upgrade!
Storage
constraints
class Person
  include DataMapper::Resource
  property :id, Serial
  property :name, String, :required => true
  property ...
class Person
  include DataMapper::Resource
  property :id, Serial
  property :name, String, :required => true
  property ...
class Person
  include DataMapper::Resource
  property :id, Serial
  property :name, String, :required => true
  property ...
class Person
  include DataMapper::Resource
  property :id, Serial
  property :name, String, :required => true
  property ...
Automatic
validations
class Person
  include DataMapper::Resource
  property :id, Serial
  property :name, String, :required => true
  property ...
class Person
      include DataMapper::Resource
      property :id, Serial
      property :name, String, :required => true...
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...
Complex
 queries
Person.all(:addresses => {:street.like => "%street%"})
Person.all(:addresses => {:street.like => "%street%"})



    SELECT   "people"."id", "people"."name", "people"."age" FROM...
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

Per...
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"...
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.defa...
Custom
adapters
module DataMapper
  module Adapters

    class MyStorageAdapter < AbstractAdapter

      def create(resources)
      end

...
Future
class Address
  include DataMapper::EmbeddedValue

  property :street,       String
end

class Person
  include DataMapper...
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/datamap...
Datamapper @ Railsconf2010
Datamapper @ Railsconf2010
Datamapper @ Railsconf2010
Datamapper @ Railsconf2010
Datamapper @ Railsconf2010
Upcoming SlideShare
Loading in...5
×

Datamapper @ Railsconf2010

3,126

Published on

DataMapper 1.0 presentation at Railsconf 2010

Published in: Technology, Business
1 Comment
10 Likes
Statistics
Notes
No Downloads
Views
Total Views
3,126
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
64
Comments
1
Likes
10
Embeds 0
No embeds

No notes for slide







































  • Transcript of "Datamapper @ Railsconf2010"

    1. 1. Dirkjan Bussink http://github.com/dbussink @dbussink
    2. 2. Why?
    3. 3. Declarative
    4. 4. class Person include DataMapper::Resource property :id, Serial property :name, String, :required => true property :age, Integer end
    5. 5. Automatic migrations
    6. 6. DataMapper.auto_migrate! DataMapper.auto_upgrade!
    7. 7. Storage constraints
    8. 8. class Person include DataMapper::Resource property :id, Serial property :name, String, :required => true property :age, Integer end
    9. 9. 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"))
    10. 10. class Person include DataMapper::Resource property :id, Serial property :name, String, :required => true property :age, Integer has n, :addresses, :constraint => :destroy! end
    11. 11. 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
    12. 12. Automatic validations
    13. 13. class Person include DataMapper::Resource property :id, Serial property :name, String, :required => true property :age, Integer end
    14. 14. 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>>
    15. 15. http://www.flickr.com/photos/jon_truran
    16. 16. Convenience
    17. 17. "that just pisses me off"
    18. 18. Lazyness
    19. 19. people = Person.all ~ Query log empty...
    20. 20. people = Person.all ~ Query log empty... p people ~ SELECT "id", "name" FROM people
    21. 21. :each
    22. 22. people = Person.all people.each do |person| p person.addresses end
    23. 23. 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))
    24. 24. Complex queries
    25. 25. Person.all(:addresses => {:street.like => "%street%"})
    26. 26. 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"
    27. 27. class Person include DataMapper::Resource ... def self.named_like_me all(:name.like => "%me%") end end
    28. 28. 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"
    29. 29. Person.all(:name.like => '%me%').addresses.all(:street.not => nil)
    30. 30. 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"
    31. 31. Person.all - Person.all(:name => 'Dan Kubb')
    32. 32. Person.all - Person.all(:name => 'Dan Kubb') SELECT * FROM people WHERE NOT(name = 'Dan Kubb')
    33. 33. Not SQL centric
    34. 34. DataMapper.setup(:default, "postgres://postgres@localhost/dm") DataMapper.setup(:docs, "mongo://user@localhost/dm")
    35. 35. class Post include DataMapper::Resource has n, :audits end class Audit include DataMapper::Resource def self.default_repository_name :log end end
    36. 36. Custom adapters
    37. 37. 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
    38. 38. Future
    39. 39. class Address include DataMapper::EmbeddedValue property :street, String end class Person include DataMapper::Resource property :id, Serial property :name, String has n, :addresses end
    40. 40. drops into2008 Back to Rails 1.0
    41. 41. 1.8 / 1.9 (on Windows too)
    42. 42. Dan Kubb Martin Gamsjaeger
    43. 43. http://datamapper.org/ http://github.com/datamapper @datamapper http://groups.google.com/group/datamapper irc://irc.freenode.net/#datamapper
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×