SlideShare ist ein Scribd-Unternehmen logo
1 von 15
Tenacity
https://github.com/jwood/tenacity

          ChicagoDB
         June 20, 2011
Polyglot Persistence is Great!
    Managing relationships...not so much
class Car
  include MongoMapper::Document
 def wheels
  Wheel.where(:car_id => self.id)
 end
end

class Wheel < ActiveRecord::Base
 # car_id defined on the table
 def car
  Car.find(self.car_id)
 end
end
Problems

• Lots of boilerplate code
• Bogus values can be stored in car_id
• What happens if the Car is deleted?
• Objects fetched from the database each time
• Adding new wheels is awkward
Introducing Tenacity
• Heavily based on ActiveRecord::Associations
• Support for has one, belongs to, and has many
  relationships
• Adds foreign key like behavior
• Can “clean up” when objects are deleted
• Related objects are fetched from the database
  once and then cached
Introducing Tenacity
• Easily work with collections of associated
  objects
• Polymorphic associations
• Read only associations
• Support for a wide array of popular Ruby
  ORM/ODM libraries
class Car
  include MongoMapper::Document
 def wheels
  Wheel.where(:car_id => self.id)
 end
end

class Wheel < ActiveRecord::Base
 # car_id defined on the table
 def car
  Car.find(self.car_id)
 end
end
class Car
  include MongoMapper::Document
  include Tenacity
 t_has_many :wheels
end

class Wheel < ActiveRecord::Base
  include Tenacity
 t_belongs_to :car
end
class Car
  include MongoMapper::Document
  include Tenacity
 t_has_many :wheels
 t_has_one :dashboard
end

class Wheel < ActiveRecord::Base
  include Tenacity
 t_belongs_to :car
end

class Dashboard < CouchRest::Model::Base
  include Tenacity
  use_database MY_DATABASE
 t_belongs_to :car
end
car = Car.create

# Set the related object
dashboard = Dashboard.create
car.dashboard = dashboard
car.save

# Fetch related object from the respective database
car.dashboard

# Fetch related object id
car.dashboard.car_id
# Set related objects
wheel_1 = Wheel.create
wheel_2 = Wheel.create
wheel_3 = Wheel.create
wheels = [wheel_1, wheel_2, wheel_3]
car.wheels = wheels
car.save

wheel_1.car_id    # car.id

# Fetch array of related objects from the respective database
car.wheels        # [wheel_1, wheel_2, wheel_3]

# Fetch ids of related objects from the database
car.wheel_ids      # [wheel_1.id, wheel_2.id, wheel_3.id]

# Add a related object to the collection
new_wheel = Wheel.create
car.wheels << new_wheel
car.save
car.wheels       # [wheel_1, wheel_2, wheel_3, new_wheel]
How Does It Work?
•   Extends supported libraries with a common set of
    methods
•   Tenacity uses these methods to work with the
    objects in a generic fashion
•   Methods are added to the model class to interact
    with the relationship
•   ORM/ODM callback functionality is used to trigger
    Tenacity to save associated objects, cleanup
    associations, etc
Supported Libraries

• ActiveRecord        • MongoMapper
  (2.x and 3.x)
                      • Mongoid
• CouchRest           • Ripple
  (CouchModel and
  ExtendedDocument)   • Sequel
• DataMapper          • Toystore
What’s On Deck?
• Add support for many to many associations
• Add support for build and create methods
 • Author.posts.build
• Improve performance
• Continue adding support for additional ORM/
  ODM libraries
Thanks!
john@johnpwood.net
    @johnpwood

Weitere ähnliche Inhalte

Ähnlich wie Tenacity

MongoDB and Ruby on Rails
MongoDB and Ruby on RailsMongoDB and Ruby on Rails
MongoDB and Ruby on Rails
rfischer20
 
Mongodb at-gilt-groupe-seattle-2012-09-14-final
Mongodb at-gilt-groupe-seattle-2012-09-14-finalMongodb at-gilt-groupe-seattle-2012-09-14-final
Mongodb at-gilt-groupe-seattle-2012-09-14-final
MongoDB
 
SharePoint Cincy 2012 - jQuery essentials
SharePoint Cincy 2012 - jQuery essentialsSharePoint Cincy 2012 - jQuery essentials
SharePoint Cincy 2012 - jQuery essentials
Mark Rackley
 
Atlanta Drupal User Group (ADUG)
Atlanta Drupal User Group (ADUG) Atlanta Drupal User Group (ADUG)
Atlanta Drupal User Group (ADUG)
Mediacurrent
 
GDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App EngineGDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App Engine
Yared Ayalew
 
DSpace 4.2 Transmission: Import/Export
DSpace 4.2 Transmission: Import/ExportDSpace 4.2 Transmission: Import/Export
DSpace 4.2 Transmission: Import/Export
DuraSpace
 
Apache Cayenne for WO Devs
Apache Cayenne for WO DevsApache Cayenne for WO Devs
Apache Cayenne for WO Devs
WO Community
 

Ähnlich wie Tenacity (20)

walkmod - JUG talk
walkmod - JUG talkwalkmod - JUG talk
walkmod - JUG talk
 
SPSNH 2014 - The SharePoint & jQueryGuide
SPSNH 2014 - The SharePoint & jQueryGuideSPSNH 2014 - The SharePoint & jQueryGuide
SPSNH 2014 - The SharePoint & jQueryGuide
 
MongoDB Basics
MongoDB BasicsMongoDB Basics
MongoDB Basics
 
MongoDB and Ruby on Rails
MongoDB and Ruby on RailsMongoDB and Ruby on Rails
MongoDB and Ruby on Rails
 
Building Your First Store App with XAML and C#
Building Your First Store App with XAML and C#Building Your First Store App with XAML and C#
Building Your First Store App with XAML and C#
 
Mongodb at-gilt-groupe-seattle-2012-09-14-final
Mongodb at-gilt-groupe-seattle-2012-09-14-finalMongodb at-gilt-groupe-seattle-2012-09-14-final
Mongodb at-gilt-groupe-seattle-2012-09-14-final
 
Web Development with Delphi and React - ITDevCon 2016
Web Development with Delphi and React - ITDevCon 2016Web Development with Delphi and React - ITDevCon 2016
Web Development with Delphi and React - ITDevCon 2016
 
SPTechCon DevDays - SharePoint & jQuery
SPTechCon DevDays - SharePoint & jQuerySPTechCon DevDays - SharePoint & jQuery
SPTechCon DevDays - SharePoint & jQuery
 
Drupal8 for Symfony Developers (PHP Day Verona 2017)
Drupal8 for Symfony Developers (PHP Day Verona 2017)Drupal8 for Symfony Developers (PHP Day Verona 2017)
Drupal8 for Symfony Developers (PHP Day Verona 2017)
 
33rd degree talk: open and automatic coding conventions with walkmod
33rd degree talk: open and automatic coding conventions with walkmod33rd degree talk: open and automatic coding conventions with walkmod
33rd degree talk: open and automatic coding conventions with walkmod
 
Stencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrivedStencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrived
 
SharePoint Cincy 2012 - jQuery essentials
SharePoint Cincy 2012 - jQuery essentialsSharePoint Cincy 2012 - jQuery essentials
SharePoint Cincy 2012 - jQuery essentials
 
Atlanta Drupal User Group (ADUG)
Atlanta Drupal User Group (ADUG) Atlanta Drupal User Group (ADUG)
Atlanta Drupal User Group (ADUG)
 
Angular mobile angular_u
Angular mobile angular_uAngular mobile angular_u
Angular mobile angular_u
 
Advanced guide to develop ajax applications using dojo
Advanced guide to develop ajax applications using dojoAdvanced guide to develop ajax applications using dojo
Advanced guide to develop ajax applications using dojo
 
GDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App EngineGDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App Engine
 
DSpace 4.2 Transmission: Import/Export
DSpace 4.2 Transmission: Import/ExportDSpace 4.2 Transmission: Import/Export
DSpace 4.2 Transmission: Import/Export
 
Apache Cayenne for WO Devs
Apache Cayenne for WO DevsApache Cayenne for WO Devs
Apache Cayenne for WO Devs
 
SPTechCon Boston 2015 - Utilizing jQuery in SharePoint
SPTechCon Boston 2015 - Utilizing jQuery in SharePointSPTechCon Boston 2015 - Utilizing jQuery in SharePoint
SPTechCon Boston 2015 - Utilizing jQuery in SharePoint
 
Wheel.js
Wheel.jsWheel.js
Wheel.js
 

Kürzlich hochgeladen

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
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
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Kürzlich hochgeladen (20)

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...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
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?
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
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
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 

Tenacity

  • 2. Polyglot Persistence is Great! Managing relationships...not so much
  • 3. class Car include MongoMapper::Document def wheels Wheel.where(:car_id => self.id) end end class Wheel < ActiveRecord::Base # car_id defined on the table def car Car.find(self.car_id) end end
  • 4. Problems • Lots of boilerplate code • Bogus values can be stored in car_id • What happens if the Car is deleted? • Objects fetched from the database each time • Adding new wheels is awkward
  • 5. Introducing Tenacity • Heavily based on ActiveRecord::Associations • Support for has one, belongs to, and has many relationships • Adds foreign key like behavior • Can “clean up” when objects are deleted • Related objects are fetched from the database once and then cached
  • 6. Introducing Tenacity • Easily work with collections of associated objects • Polymorphic associations • Read only associations • Support for a wide array of popular Ruby ORM/ODM libraries
  • 7. class Car include MongoMapper::Document def wheels Wheel.where(:car_id => self.id) end end class Wheel < ActiveRecord::Base # car_id defined on the table def car Car.find(self.car_id) end end
  • 8. class Car include MongoMapper::Document include Tenacity t_has_many :wheels end class Wheel < ActiveRecord::Base include Tenacity t_belongs_to :car end
  • 9. class Car include MongoMapper::Document include Tenacity t_has_many :wheels t_has_one :dashboard end class Wheel < ActiveRecord::Base include Tenacity t_belongs_to :car end class Dashboard < CouchRest::Model::Base include Tenacity use_database MY_DATABASE t_belongs_to :car end
  • 10. car = Car.create # Set the related object dashboard = Dashboard.create car.dashboard = dashboard car.save # Fetch related object from the respective database car.dashboard # Fetch related object id car.dashboard.car_id
  • 11. # Set related objects wheel_1 = Wheel.create wheel_2 = Wheel.create wheel_3 = Wheel.create wheels = [wheel_1, wheel_2, wheel_3] car.wheels = wheels car.save wheel_1.car_id # car.id # Fetch array of related objects from the respective database car.wheels # [wheel_1, wheel_2, wheel_3] # Fetch ids of related objects from the database car.wheel_ids # [wheel_1.id, wheel_2.id, wheel_3.id] # Add a related object to the collection new_wheel = Wheel.create car.wheels << new_wheel car.save car.wheels # [wheel_1, wheel_2, wheel_3, new_wheel]
  • 12. How Does It Work? • Extends supported libraries with a common set of methods • Tenacity uses these methods to work with the objects in a generic fashion • Methods are added to the model class to interact with the relationship • ORM/ODM callback functionality is used to trigger Tenacity to save associated objects, cleanup associations, etc
  • 13. Supported Libraries • ActiveRecord • MongoMapper (2.x and 3.x) • Mongoid • CouchRest • Ripple (CouchModel and ExtendedDocument) • Sequel • DataMapper • Toystore
  • 14. What’s On Deck? • Add support for many to many associations • Add support for build and create methods • Author.posts.build • Improve performance • Continue adding support for additional ORM/ ODM libraries

Hinweis der Redaktion

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n