SlideShare une entreprise Scribd logo
1  sur  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

Contenu connexe

Similaire à 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
 

Similaire à 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
 

Dernier

Dernier (20)

Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
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...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
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
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
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
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
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
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
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
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
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
 
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...
 
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
 
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)
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 

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

Notes de l'éditeur

  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