Your SlideShare is downloading. ×
0
Datamapper @ Railsconf2010
Datamapper @ Railsconf2010
Datamapper @ Railsconf2010
Datamapper @ Railsconf2010
Datamapper @ Railsconf2010
Datamapper @ Railsconf2010
Datamapper @ Railsconf2010
Datamapper @ Railsconf2010
Datamapper @ Railsconf2010
Datamapper @ Railsconf2010
Datamapper @ Railsconf2010
Datamapper @ Railsconf2010
Datamapper @ Railsconf2010
Datamapper @ Railsconf2010
Datamapper @ Railsconf2010
Datamapper @ Railsconf2010
Datamapper @ Railsconf2010
Datamapper @ Railsconf2010
Datamapper @ Railsconf2010
Datamapper @ Railsconf2010
Datamapper @ Railsconf2010
Datamapper @ Railsconf2010
Datamapper @ Railsconf2010
Datamapper @ Railsconf2010
Datamapper @ Railsconf2010
Datamapper @ Railsconf2010
Datamapper @ Railsconf2010
Datamapper @ Railsconf2010
Datamapper @ Railsconf2010
Datamapper @ Railsconf2010
Datamapper @ Railsconf2010
Datamapper @ Railsconf2010
Datamapper @ Railsconf2010
Datamapper @ Railsconf2010
Datamapper @ Railsconf2010
Datamapper @ Railsconf2010
Datamapper @ Railsconf2010
Datamapper @ Railsconf2010
Datamapper @ Railsconf2010
Datamapper @ Railsconf2010
Datamapper @ Railsconf2010
Datamapper @ Railsconf2010
Datamapper @ Railsconf2010
Datamapper @ Railsconf2010
Datamapper @ Railsconf2010
Datamapper @ Railsconf2010
Datamapper @ Railsconf2010
Datamapper @ Railsconf2010
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Datamapper @ Railsconf2010

3,091

Published on

DataMapper 1.0 presentation at Railsconf 2010

DataMapper 1.0 presentation at Railsconf 2010

Published in: Technology, Business
1 Comment
10 Likes
Statistics
Notes
No Downloads
Views
Total Views
3,091
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
64
Comments
1
Likes
10
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. Dirkjan Bussink http://github.com/dbussink @dbussink
    • 2. Why?
    • 3. Declarative
    • 4. class Person include DataMapper::Resource property :id, Serial property :name, String, :required => true property :age, Integer end
    • 5. Automatic migrations
    • 6. DataMapper.auto_migrate! DataMapper.auto_upgrade!
    • 7. Storage constraints
    • 8. class Person include DataMapper::Resource property :id, Serial property :name, String, :required => true property :age, Integer end
    • 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. class Person include DataMapper::Resource property :id, Serial property :name, String, :required => true property :age, Integer has n, :addresses, :constraint => :destroy! end
    • 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. Automatic validations
    • 13. class Person include DataMapper::Resource property :id, Serial property :name, String, :required => true property :age, Integer end
    • 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. http://www.flickr.com/photos/jon_truran
    • 16. Convenience
    • 17. "that just pisses me off"
    • 18. Lazyness
    • 19. people = Person.all ~ Query log empty...
    • 20. people = Person.all ~ Query log empty... p people ~ SELECT "id", "name" FROM people
    • 21. :each
    • 22. people = Person.all people.each do |person| p person.addresses end
    • 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. Complex queries
    • 25. Person.all(:addresses => {:street.like => "%street%"})
    • 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. class Person include DataMapper::Resource ... def self.named_like_me all(:name.like => "%me%") end end
    • 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. Person.all(:name.like => '%me%').addresses.all(:street.not => nil)
    • 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. Person.all - Person.all(:name => 'Dan Kubb')
    • 32. Person.all - Person.all(:name => 'Dan Kubb') SELECT * FROM people WHERE NOT(name = 'Dan Kubb')
    • 33. Not SQL centric
    • 34. DataMapper.setup(:default, "postgres://postgres@localhost/dm") DataMapper.setup(:docs, "mongo://user@localhost/dm")
    • 35. class Post include DataMapper::Resource has n, :audits end class Audit include DataMapper::Resource def self.default_repository_name :log end end
    • 36. Custom adapters
    • 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. Future
    • 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. drops into2008 Back to Rails 1.0
    • 41. 1.8 / 1.9 (on Windows too)
    • 42. Dan Kubb Martin Gamsjaeger
    • 43. http://datamapper.org/ http://github.com/datamapper @datamapper http://groups.google.com/group/datamapper irc://irc.freenode.net/#datamapper

    ×