Data Mapper Krug 8

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Favorites, Groups & Events

    Data Mapper Krug 8 - Presentation Transcript

    1. BY PIOTR SOLNICA
    2. Plan Prezentacji
      • Istniejące Implementacje ORM
      • Architektura
        • Repozytoria
        • Adaptery
        • Zasoby
      • Podstawy
      • Key Features
      • Status projektu
      November 19, 2008 © Piotr Solnica
    3. DataMapper Istniejące Implementacje ORM November 19, 2008 © Piotr Solnica
    4. Istniejące Implementacje ORM ActiveRecord & Sequel November 19, 2008 © Piotr Solnica
    5. Istniejące Implementacje ORM Po co trzeci zawodnik…? November 19, 2008 © Piotr Solnica
    6. Istniejące Implementacje ORM
      • ActiveRecord:
        • Kiepska architektura – obsługuje tylko relacyjne bazy danych i do tego nie wie czym jest klucz złożony…
        • Dużo wtyczek, przy czym każdy update powoduje, że połowa przestaje działać
        • Szybki kosztem pamięci
        • Frustrujące API!
      November 19, 2008 © Piotr Solnica
    7. Istniejące Implementacje ORM
      • Sequel:
        • Trochę lepszy ActiveRecord
      November 19, 2008 © Piotr Solnica
    8. Istniejące implementacje ORM November 19, 2008 © Piotr Solnica
    9. Istniejące Implementacje ORM Poza tym wszystkim… November 19, 2008 © Piotr Solnica
    10. Istniejące Implementacje ORM … ActiveRecord & Sequel używają… November 19, 2008 © Piotr Solnica
    11. Istniejące Implementacje ORM MIGRACJI! November 19, 2008 © Piotr Solnica
    12. Istniejące Implementacje ORM DataMapper November 19, 2008 © Piotr Solnica
    13. DataMapper Architektura November 19, 2008 © Piotr Solnica
    14. DataMapper / Architektura Repozytoria MySQL CauchDB SimpleDB Adaptery Zasoby November 19, 2008 © Piotr Solnica
    15. DataMapper / Architektura Repozytoria November 19, 2008 © Piotr Solnica
    16. DataMapper / Architektura / Repozytoria
      • Repozytoria są to źródła danych, na przykład:
        • relacyjne bazy danych (doooh!)
        • obiektowe bazy danych
        • systemy plików
        • YAML, JSON, XML itd.
        • Amazon SimpleDB
        • REST-based
      November 19, 2008 © Piotr Solnica
    17. DataMapper / Architektura / Repozytoria Każdy system udostępniający dane za pomocą swojego interfejsu może stać się repozytorium DataMappera November 19, 2008 © Piotr Solnica
    18. DataMapper / Architektura Adaptery November 19, 2008 © Piotr Solnica
    19. DataMapper / Architektura / Adaptery Adaptery zapewniają transparentny dostęp do danych z repozytoriów November 19, 2008 © Piotr Solnica
    20. DataMapper / Architektura / Adaptery
      • Istniejące adaptery:
        • MySQL / Postgres / SQLite
        • YAML
        • CSV
        • CouchDB
        • Amazon SimpleDB
        • Ferret
        • IMAP
        • … masa innych under development 
      November 19, 2008 © Piotr Solnica
    21. DataMapper / Architetura Zasoby November 19, 2008 © Piotr Solnica
    22. DataMapper / Architektura / Zasoby Zasoby reprezentują dane z repozytoriów, za ich pośrednictwem wykonujemy operacje CRUD November 19, 2008 © Piotr Solnica
    23. DataMapper / Architektura / Zasoby Każdy zasób charakteryzuje się różnymi własnościami, przy czym własności te mogą być związane z różnymi repozytoriami… November 19, 2008 © Piotr Solnica
    24. DataMapper / Architektura / Zasoby … to my decydujemy jakie własności zasobów nas interesują, a nie zautomatyzowany do bólu ORM! November 19, 2008 © Piotr Solnica
    25. DataMapper / Architektura / Zasoby Pomiędzy zasobami mogą istnieć powiązania typowe dla relacyjnych baz danych (one-to-one, one-to-many etc.) November 19, 2008 © Piotr Solnica
    26. DataMapper Podstawy November 19, 2008 © Piotr Solnica
    27. DataMapper / Podstawy dm-core & dm-more November 19, 2008 © Piotr Solnica
    28. DataMapper / Podstawy
      • Trzy poziomy API:
        • public
        • semi-public
        • private
      November 19, 2008 © Piotr Solnica
    29. DataMapper / Podstawy Własności modelu deklaruje się na poziomie jego klasy! class Zoo include DataMapper::Resource property :id, Serial property :name, String end November 19, 2008 © Piotr Solnica
    30. DataMapper / Podstawy Relacje class Zoo include DataMapper::Resource property :id, Serial property :name, String has n, :animals has 1..10 , :young_animals, :class_name => ‘Animal’, :age => 1..3 end class Animal include DataMapper::Resource property :id, Serial property :name, String property :age, Integer belongs_to :zoo end November 19, 2008 © Piotr Solnica
    31. DataMapper / Podstawy Automigracje Zoo.auto_migrate! Zoo.auto_upgrade! November 19, 2008 © Piotr Solnica
    32. DataMapper / Podstawy Tworzenie nowych zasobów some_zoo = Zoo.create(:name => ‘Some Zoo’) some_zoo.animals.create(:name => ‘Marty’) another_zoo = Zoo.new(:name => ‘Another Zoo’) another_animal = Animal.new( :name => ‘Alex’, :zoo => another_zoo) another_zoo.save another_animal.save November 19, 2008 © Piotr Solnica
    33. DataMapper / Podstawy Pobieranie zasobów zoo = Zoo.get(1) zoo.animals.get(1) zoo = Zoo.first(:name => ‘Some Zoo’) zoo.animals.all(:name => ‘Marty’) November 19, 2008 © Piotr Solnica
    34. DataMapper / Podstawy Callbacks class Zoo include DataMapper::Resource property :id, Serial property :name, String before :save do name = ‘Default Name’ if name.blank? end end November 19, 2008 © Piotr Solnica
    35. DataMapper Key Features November 19, 2008 © Piotr Solnica
    36. DataMapper / Key Features IdentityMap repository do marty1 = Zoo.get( 1 ) marty2 = Zoo.get( 1 ) marty1.object_id == marty2.object_id # true end November 19, 2008 © Piotr Solnica
    37. DataMapper / Key Features Animal.create(:name => ‘Marty’, :age => 12 ) marty = Animal.first(:name => 'Marty' ) marty.attribute_dirty?(:age) # false marty.age = 21 marty.attribute_dirty?(:age) # false marty.save # UPDATE `animals` SET `age` = 21 WHERE (`id` = 1) Dirty Properties Tracking November 19, 2008 © Piotr Solnica
    38. DataMapper / Key Features class Zoo include DataMapper::Resource property :id, Serial property :description, Text end Zoo.create(:description => ‘This is a very nice zoo’) # SELECT `id` FROM `zoos` WHERE (`id` = 1) ORDER BY `id` LIMIT 1 zoo = Zoo.get(zoo1.id) # SELECT `description`, `id` FROM `zoos` WHERE (`id` = 1) ORDER BY `id` zoo.description Lazy Loading November 19, 2008 © Piotr Solnica
    39. DataMapper / Key Features zoos = Zoo.all # nie wykonuje się żadne zapytanie! zoos.each do |zoo| # dopiero tutaj zostaną pobrane wszystkie zoo zoo.animals.each do |animal| # a tutaj wszystkie animals należące do zoos! puts "Animal #{animal.name} from #{zoo.name}" end end Strategic Eager Loading November 19, 2008 © Piotr Solnica
    40. DataMapper / Key Features class Zoo include DataMapper::Resource property :id, Serial end class Cage include DataMapper::Resource property :id, Serial end class Animal include DataMapper::Resource property :zoo_id, :key => true property :cage_id, :key => true end Composite Keys November 19, 2008 © Piotr Solnica
    41. DataMapper / Key Features zoo = Zoo.create cage = Cage.create(:zoo => zoo) Animal.create(:zoo => zoo, :cage => cage) animal = Animal.get(zoo.id, cage.id) Composite Keys November 19, 2008 © Piotr Solnica
    42. DataMapper / Key Features class Zoo include DataMapper::Resource property :id, Serial property :name, String, :length => 12..64 end zoo = Zoo.new(:name => ‘Too short’) # ["Name must be between 12 and 64 characters long"] zoo.errors[:name] Auto-Validations November 19, 2008 © Piotr Solnica
    43. DataMapper / Key Features class Article include DataMapper::Resource property :id, Serial property :title, String property :body, Text validates_present :title, : when => [:publish] validates_length :body, :minimum => 1000 , : when => [:publish] end article = Article.new article.valid_for_publish? # false article.title = 'Hello World' article.valid_for_publish? # false article.body = '...some 1000 chars text...' article.valid_for_publish? # true! Contextual Validations November 19, 2008 © Piotr Solnica
    44. DataMapper / Key Features class User include DataMapper::Resource property :id, Serial property :postal_code, PostalCode end user = User.new(:postal_code => '12-34' ) user.valid? # false user.errors[:postal_code] # ["Postal code has an invalid format"] user.postal_code = '12-345' user.valid? # true Custom Data Types November 19, 2008 © Piotr Solnica
    45. DataMapper / Key Features module DataMapper module Types class PostalCode < DataMapper::Type primitive String format(/^d{ 2 }-d{ 3 }$/) end end end Custom Data Types November 19, 2008 © Piotr Solnica
    46. DataMapper Status Projektu November 19, 2008 © Piotr Solnica
    47. DataMapper / Status Projektu CURRENT VERSION: 0.9.6 November 19, 2008 © Piotr Solnica
    48. DataMapper Pytania? November 19, 2008 © Piotr Solnica
    49. DataMapper Dziękuję November 19, 2008 © Piotr Solnica

    + Paul KlippPaul Klipp, 2 years ago

    custom

    769 views, 0 favs, 0 embeds more stats

    Piotr's presentation on Datamapper and Merb at the more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 769
      • 769 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 11
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories