SlideShare una empresa de Scribd logo
1 de 25
To use an ORM
or not to use an ORM?
Harro Verton @ CICONF 2012, London, UK
Who is this guy?

• Digitally known as WanWizard
• Partner in Exite, an ICT company in the Netherlands
• Runs Exite’s Development and Hosting business
• In software development for over 30 years
• Loves writing code whenever time permits
   • DataMapper ORM
   • Modular CI
   • FuelPHP Core developer
• Hates being reminded of his age!




                                                        © Harro Verton, Exite BV, 2012
So, what is an ORM?

• Object Relational Mapping
• Programming technique to map scalar data into objects
  with full knowledge of their relationship with other objects

                                                           Object   Object




                                                           Object




                                                           Object

 Martin Fowler, Patterns of Enterprise Application Architecture
                                                                     © Harro Verton, Exite BV, 2012
Architectural design patterns

Active Record pattern              Data Mapper pattern




• Other patterns exist, but are not widely used
   • Table Data Gateway
        basic singleton model per table
   • Row Data Gateway
        separates table and row singletons

                                                         © Harro Verton, Exite BV, 2012
Active Record pattern

• A design pattern where an object is represented as a record
  on a table in a relational database
• Very efficient due to the assumption “1 object = 1 record”
• Relationship from object  database
• Configuration driven, not schema dependent
• Code and data in a single object
• Very fast if implemented properly
• Used by most ORM implementations


• CodeIgniter’s Active Record is NOT an
  Active Record pattern, it’s a Query Builder!

                                                      © Harro Verton, Exite BV, 2012
Data Mapper pattern

• A design pattern where an object represents a data
  collection
• More flexible, a collection can be anything
• Mapping code is separated from data
• Relationship from datastore  object
• Complexity and flexibility comes at a cost
• Less efficient  more overhead  slower
• Not very widely used




                                                       © Harro Verton, Exite BV, 2012
Related patterns

• Unit of Work pattern
    • Maintains a list of objects affected by a business transaction
      and coordinates the writing out of changes and the resolution
      of concurrency problems.
• Identity Map pattern
    • Ensures that each object gets loaded only once by keeping
      every loaded object in a map. Looks up objects using the map
      when referring to them.
• Lazy Load pattern
    • An object that doesn't contain all of the data you need but
      knows how to get it.
• Most ORM implementations can't be bothered!

 Matt Zandstra, PHP Objects, Patterns and Practice, 3rd edition
                                                                   © Harro Verton, Exite BV, 2012
Are you still with me? Good!




                               © Harro Verton, Exite BV, 2012
OK. Now why would you use an ORM?

• Object oriented access to your data
• Unified access to your data
• Abstracting the underlying storage mechanism
   • Both for the storage platform and the data access language
• Abstracting complexity of data manipulation
• Reduces the time to develop an application
• Easier and faster application maintenance




                                                          © Harro Verton, Exite BV, 2012
And why should you not?

• Every abstraction layer adds processing time
• Lots of objects  lots of memory needed
• Generated queries can be sub-optimal
• An ORM can not generate all queries possible
• Some ORM’s duplicate the database layer
• Some ORM’s don’t save you much development time
  due to their complex implementation




                                                 © Harro Verton, Exite BV, 2012
Work around the issues

• Lots of objects  lots of memory needed
   • Think carefully about what you fetch
   • Use standard DB calls when manipulating large volumes
• Generated queries can be sub-optimal, or
• An ORM can not generate all queries possible
   • Determine if this really is a problem for your application
   • Some ORM’s allow custom SQL
   • Fall back to standard DB calls as a last resort
• Some ORM’s don’t save you much development time
  due to their complex implementation.
   • Ask yourself: did I make the correct choice?

                                                             © Harro Verton, Exite BV, 2012
It also depends on your situation

• Your time is free, and no money for servers?
    Code low-level, every CPU cycle counts!
• Your code has to be maintained by others?
    Using an ORM is probably a good idea
 You’re working in a team, and time == money?
    ORM is the way to go, and use separate models too!
 The message here is:
    CPU Power is cheap
    Good developers are expensive
    Spend money where it counts!



                                                          © Harro Verton, Exite BV, 2012
Good. No more theory.




Awake again?

                        © Harro Verton, Exite BV, 2012
Using an ORM in an MVC framework


                                                 Database
 Request                        Models             ORM
                                                  Layer

               Controller


 Response                       Views




• The ORM is your data abstraction layer
• The Model contains your business logic
• What not to do:
    have the business logic in the controller
     and use the ORM as your model
 Some ORM’s allow you to merge the functionality
  of the Model and the ORM
    but think carefully about the complexity…
                                                            © Harro Verton, Exite BV, 2012
Some ORM’s that can be used with CI

• Active Record based
   • Datamapper ORM        (http://datamapper.wanwizard.eu)

   • Propel   (http://www.propelorm.org)

   • NitroORM    (http://nitro-orm.net)

   • PHP ActiveRecord (http://www.phpactiverecord.org)
   • GAS ORM (http://gasorm-doc.taufanaditya.com)
   • Ignited Record    (http://www.assembla.com/spaces/IgnitedRecord/wiki)

• Data Mapper based
   • Doctrine   (http://www.doctrine-project.org)

• There are more…


                                                                     © Harro Verton, Exite BV, 2012
Datamapper ORM

• Pro’s:
   • Around for a very long time ( < 2008 )
   • Very stable and full-featured API
   • Fully integrated into CI
• Con’s:
   • Code base has aged due to CI’s PHP4 support
   • Implemented as a Model base class




                                                   © Harro Verton, Exite BV, 2012
Propel

• Pro’s:
   • Around even longer ( since 2005 )
   • Very rich feature set
• Con’s:
   • Has it’s own database layer
   • Uses XML schema’s to generate the model code
   • Requires command-line access




                                                    © Harro Verton, Exite BV, 2012
NitroORM

• Pro’s:
   • Very promising feature roadmap
• Con’s:
   • Very new ( 7 months ), not mature
   • Lots of features still missing
   • No visible activity after the last release ( 11/2011 )
   • Requires PHP 5.3+ ( note that CI only requires 5.1.6+ )
        Your host might not support it!

   • Documentation is very sparse




                                                              © Harro Verton, Exite BV, 2012
PHP ActiveRecord

• Pro’s:
   • Complete feature set, including validation
   • CI integration available ( how-to or using a spark )
• Con’s:
   • No visible activity:
       • Last stable release almost 2 years old
       • Last nightly build 5 months old




                                                            © Harro Verton, Exite BV, 2012
GAS ORM

• Pro’s:
   • Fully integrated into CI
   • Built-in query caching
• Con’s:
   • Only a few months old, no roadmap known
   • Not a lot of documentation available




                                               © Harro Verton, Exite BV, 2012
Ignited Record

• Pro’s:
   • Eh...
• Con’s:
   • No visible activity since 2008
   • Compatible with CI 2.x?
• Consider this one dead and buried…




                                       © Harro Verton, Exite BV, 2012
Doctrine

• Pro’s:
   • Full featured, implements the full “Fowler stack”
• Con’s:
   • Uses a command line interface
   • Very complex to work with
   • No query methods, the DQL must be used




                                                         © Harro Verton, Exite BV, 2012
Considerations when making a choice

• Does my project benefit from using an ORM?
• Which pattern am I going to use?
• Does it have all functionality my project requires?
• How about support and documentation?
• Other considerations:
   • How easy is the integration into CodeIgniter?
   • Do they provide CodeIgniter support?
   • How large is the user base?
   • Is it still actively maintained?
   • Is their code stable enough to invest time in?
   • Check the CI forums for possible issues!

                                                        © Harro Verton, Exite BV, 2012
Question
  Time !



      © Harro Verton, Exite BV, 2012
Thank you for attending!

• Tomorrow:
   • Masterclass on Datamapper ORM
   • Download the files from the programme page on the website


• More questions?
   • Find me here today or tomorrow
   • Use the CodeIgniter forums
   • Twitter: @WanWizard
   • Email: codeigniter@wanwizard.eu




                                                        © Harro Verton, Exite BV, 2012

Más contenido relacionado

Destacado

Metadata Design Project
Metadata Design ProjectMetadata Design Project
Metadata Design Projecthuangmz
 
Building Data Mapper PHP5
Building Data Mapper PHP5Building Data Mapper PHP5
Building Data Mapper PHP5Vance Lucas
 
REPORT IN PRODMAN Testing models and Examples
REPORT IN PRODMAN Testing models and Examples REPORT IN PRODMAN Testing models and Examples
REPORT IN PRODMAN Testing models and Examples Kevin Lime
 
Practical Data Dictionary -
Practical Data Dictionary -Practical Data Dictionary -
Practical Data Dictionary -Data36
 
Enterprise PHP: mappers, models and services
Enterprise PHP: mappers, models and servicesEnterprise PHP: mappers, models and services
Enterprise PHP: mappers, models and servicesAaron Saray
 
071310 obama email (welsh)
071310   obama email (welsh)071310   obama email (welsh)
071310 obama email (welsh)VogelDenise
 
072712 usa ku klux klan runned government - chinese (traditional)
072712 usa ku klux klan runned government - chinese (traditional)072712 usa ku klux klan runned government - chinese (traditional)
072712 usa ku klux klan runned government - chinese (traditional)VogelDenise
 
Urdu 021912 email tounitedstatescongress
Urdu   021912 email tounitedstatescongressUrdu   021912 email tounitedstatescongress
Urdu 021912 email tounitedstatescongressVogelDenise
 
072712 usa ku klux klan runned government - norwegian
072712 usa ku klux klan runned government - norwegian072712 usa ku klux klan runned government - norwegian
072712 usa ku klux klan runned government - norwegianVogelDenise
 
GEORGE ZIMMERMAN'S NOT GUILTY VERDICT - NOT SO FAST (czech)
GEORGE ZIMMERMAN'S NOT GUILTY VERDICT - NOT SO FAST (czech)GEORGE ZIMMERMAN'S NOT GUILTY VERDICT - NOT SO FAST (czech)
GEORGE ZIMMERMAN'S NOT GUILTY VERDICT - NOT SO FAST (czech)VogelDenise
 
102912 vogel denise slideshare documents (russian)
102912   vogel denise slideshare documents (russian)102912   vogel denise slideshare documents (russian)
102912 vogel denise slideshare documents (russian)VogelDenise
 
Barack obama christian or heathen (catalan)
Barack obama   christian or heathen (catalan)Barack obama   christian or heathen (catalan)
Barack obama christian or heathen (catalan)VogelDenise
 
092712 julian assange (president obama's audacity) - danish
092712   julian assange (president obama's audacity) - danish092712   julian assange (president obama's audacity) - danish
092712 julian assange (president obama's audacity) - danishVogelDenise
 
031808 obama speech (romanian)
031808   obama speech (romanian)031808   obama speech (romanian)
031808 obama speech (romanian)VogelDenise
 
031808 obama speech (telugu)
031808   obama speech (telugu)031808   obama speech (telugu)
031808 obama speech (telugu)VogelDenise
 
092712 julian assange (president obama's audacity) - finnish
092712   julian assange (president obama's audacity) - finnish092712   julian assange (president obama's audacity) - finnish
092712 julian assange (president obama's audacity) - finnishVogelDenise
 

Destacado (18)

Metadata Design Project
Metadata Design ProjectMetadata Design Project
Metadata Design Project
 
Building Data Mapper PHP5
Building Data Mapper PHP5Building Data Mapper PHP5
Building Data Mapper PHP5
 
interface sample
interface sampleinterface sample
interface sample
 
REPORT IN PRODMAN Testing models and Examples
REPORT IN PRODMAN Testing models and Examples REPORT IN PRODMAN Testing models and Examples
REPORT IN PRODMAN Testing models and Examples
 
Practical Data Dictionary -
Practical Data Dictionary -Practical Data Dictionary -
Practical Data Dictionary -
 
Python Comparing ORM
Python Comparing ORMPython Comparing ORM
Python Comparing ORM
 
Enterprise PHP: mappers, models and services
Enterprise PHP: mappers, models and servicesEnterprise PHP: mappers, models and services
Enterprise PHP: mappers, models and services
 
071310 obama email (welsh)
071310   obama email (welsh)071310   obama email (welsh)
071310 obama email (welsh)
 
072712 usa ku klux klan runned government - chinese (traditional)
072712 usa ku klux klan runned government - chinese (traditional)072712 usa ku klux klan runned government - chinese (traditional)
072712 usa ku klux klan runned government - chinese (traditional)
 
Urdu 021912 email tounitedstatescongress
Urdu   021912 email tounitedstatescongressUrdu   021912 email tounitedstatescongress
Urdu 021912 email tounitedstatescongress
 
072712 usa ku klux klan runned government - norwegian
072712 usa ku klux klan runned government - norwegian072712 usa ku klux klan runned government - norwegian
072712 usa ku klux klan runned government - norwegian
 
GEORGE ZIMMERMAN'S NOT GUILTY VERDICT - NOT SO FAST (czech)
GEORGE ZIMMERMAN'S NOT GUILTY VERDICT - NOT SO FAST (czech)GEORGE ZIMMERMAN'S NOT GUILTY VERDICT - NOT SO FAST (czech)
GEORGE ZIMMERMAN'S NOT GUILTY VERDICT - NOT SO FAST (czech)
 
102912 vogel denise slideshare documents (russian)
102912   vogel denise slideshare documents (russian)102912   vogel denise slideshare documents (russian)
102912 vogel denise slideshare documents (russian)
 
Barack obama christian or heathen (catalan)
Barack obama   christian or heathen (catalan)Barack obama   christian or heathen (catalan)
Barack obama christian or heathen (catalan)
 
092712 julian assange (president obama's audacity) - danish
092712   julian assange (president obama's audacity) - danish092712   julian assange (president obama's audacity) - danish
092712 julian assange (president obama's audacity) - danish
 
031808 obama speech (romanian)
031808   obama speech (romanian)031808   obama speech (romanian)
031808 obama speech (romanian)
 
031808 obama speech (telugu)
031808   obama speech (telugu)031808   obama speech (telugu)
031808 obama speech (telugu)
 
092712 julian assange (president obama's audacity) - finnish
092712   julian assange (president obama's audacity) - finnish092712   julian assange (president obama's audacity) - finnish
092712 julian assange (president obama's audacity) - finnish
 

Similar a How to use ORM

Lean Startup with WebObjects
Lean Startup with WebObjectsLean Startup with WebObjects
Lean Startup with WebObjectsWO Community
 
Introduction to Aspect Oriented Programming by Donald Belcham
Introduction to Aspect Oriented Programming by Donald BelchamIntroduction to Aspect Oriented Programming by Donald Belcham
Introduction to Aspect Oriented Programming by Donald Belcham.NET Conf UY
 
Putting Compilers to Work
Putting Compilers to WorkPutting Compilers to Work
Putting Compilers to WorkSingleStore
 
Advanced dev ops governance with terraform
Advanced dev ops governance with terraformAdvanced dev ops governance with terraform
Advanced dev ops governance with terraformJames Counts
 
2005 04 05 SRI ELN Architecture
2005 04 05 SRI ELN Architecture2005 04 05 SRI ELN Architecture
2005 04 05 SRI ELN ArchitectureSimon Coles
 
2018-09 - F# and Fable
2018-09 - F# and Fable2018-09 - F# and Fable
2018-09 - F# and FableEamonn Boyle
 
FDM, ERPi, EPMA, DRM, EAL - Understanding the Alphabet Soup of Integration
FDM, ERPi, EPMA, DRM, EAL - Understanding the Alphabet Soup of IntegrationFDM, ERPi, EPMA, DRM, EAL - Understanding the Alphabet Soup of Integration
FDM, ERPi, EPMA, DRM, EAL - Understanding the Alphabet Soup of IntegrationAlithya
 
PHP Frameworks Review - Mar 19 2015
PHP Frameworks Review - Mar 19 2015PHP Frameworks Review - Mar 19 2015
PHP Frameworks Review - Mar 19 2015kyphpug
 
eFolder Partner Chat Webinar — Getting Started on the Right Foot with BDR
eFolder Partner Chat Webinar — Getting Started on the Right Foot with BDReFolder Partner Chat Webinar — Getting Started on the Right Foot with BDR
eFolder Partner Chat Webinar — Getting Started on the Right Foot with BDReFolder
 
Babysitting your orm essenmacher, adam
Babysitting your orm   essenmacher, adamBabysitting your orm   essenmacher, adam
Babysitting your orm essenmacher, adamAdam Essenmacher
 
10 clues showing that you are doing OSGi in the wrong manner - Jerome Moliere
10 clues showing that you are doing OSGi in the wrong manner - Jerome Moliere10 clues showing that you are doing OSGi in the wrong manner - Jerome Moliere
10 clues showing that you are doing OSGi in the wrong manner - Jerome Molieremfrancis
 
How to guarantee your change is integrated to Moodle core
How to guarantee your change is integrated to Moodle coreHow to guarantee your change is integrated to Moodle core
How to guarantee your change is integrated to Moodle coreDan Poltawski
 
Client Technical Analysis of Legacy Software and Future Replacement
Client Technical Analysis of Legacy Software and Future ReplacementClient Technical Analysis of Legacy Software and Future Replacement
Client Technical Analysis of Legacy Software and Future ReplacementVictorSzoltysek
 
NetWork - 15.10.2011 - Applied code generation in .NET
NetWork - 15.10.2011 - Applied code generation in .NET NetWork - 15.10.2011 - Applied code generation in .NET
NetWork - 15.10.2011 - Applied code generation in .NET Dmytro Mindra
 
Model-driven and low-code development for event-based systems | Bobby Calderw...
Model-driven and low-code development for event-based systems | Bobby Calderw...Model-driven and low-code development for event-based systems | Bobby Calderw...
Model-driven and low-code development for event-based systems | Bobby Calderw...HostedbyConfluent
 
My cool new Slideshow!
My cool new Slideshow!My cool new Slideshow!
My cool new Slideshow!netzwelt12345
 
Rebooting design in RavenDB
Rebooting design in RavenDBRebooting design in RavenDB
Rebooting design in RavenDBOren Eini
 

Similar a How to use ORM (20)

Lean Startup with WebObjects
Lean Startup with WebObjectsLean Startup with WebObjects
Lean Startup with WebObjects
 
Introduction to Aspect Oriented Programming by Donald Belcham
Introduction to Aspect Oriented Programming by Donald BelchamIntroduction to Aspect Oriented Programming by Donald Belcham
Introduction to Aspect Oriented Programming by Donald Belcham
 
Introduction To AOP
Introduction To AOPIntroduction To AOP
Introduction To AOP
 
Putting Compilers to Work
Putting Compilers to WorkPutting Compilers to Work
Putting Compilers to Work
 
Advanced dev ops governance with terraform
Advanced dev ops governance with terraformAdvanced dev ops governance with terraform
Advanced dev ops governance with terraform
 
Intro To AOP
Intro To AOPIntro To AOP
Intro To AOP
 
2005 04 05 SRI ELN Architecture
2005 04 05 SRI ELN Architecture2005 04 05 SRI ELN Architecture
2005 04 05 SRI ELN Architecture
 
2018-09 - F# and Fable
2018-09 - F# and Fable2018-09 - F# and Fable
2018-09 - F# and Fable
 
FDM, ERPi, EPMA, DRM, EAL - Understanding the Alphabet Soup of Integration
FDM, ERPi, EPMA, DRM, EAL - Understanding the Alphabet Soup of IntegrationFDM, ERPi, EPMA, DRM, EAL - Understanding the Alphabet Soup of Integration
FDM, ERPi, EPMA, DRM, EAL - Understanding the Alphabet Soup of Integration
 
PHP Frameworks Review - Mar 19 2015
PHP Frameworks Review - Mar 19 2015PHP Frameworks Review - Mar 19 2015
PHP Frameworks Review - Mar 19 2015
 
eFolder Partner Chat Webinar — Getting Started on the Right Foot with BDR
eFolder Partner Chat Webinar — Getting Started on the Right Foot with BDReFolder Partner Chat Webinar — Getting Started on the Right Foot with BDR
eFolder Partner Chat Webinar — Getting Started on the Right Foot with BDR
 
Babysitting your orm essenmacher, adam
Babysitting your orm   essenmacher, adamBabysitting your orm   essenmacher, adam
Babysitting your orm essenmacher, adam
 
10 clues showing that you are doing OSGi in the wrong manner - Jerome Moliere
10 clues showing that you are doing OSGi in the wrong manner - Jerome Moliere10 clues showing that you are doing OSGi in the wrong manner - Jerome Moliere
10 clues showing that you are doing OSGi in the wrong manner - Jerome Moliere
 
How to guarantee your change is integrated to Moodle core
How to guarantee your change is integrated to Moodle coreHow to guarantee your change is integrated to Moodle core
How to guarantee your change is integrated to Moodle core
 
Client Technical Analysis of Legacy Software and Future Replacement
Client Technical Analysis of Legacy Software and Future ReplacementClient Technical Analysis of Legacy Software and Future Replacement
Client Technical Analysis of Legacy Software and Future Replacement
 
NetWork - 15.10.2011 - Applied code generation in .NET
NetWork - 15.10.2011 - Applied code generation in .NET NetWork - 15.10.2011 - Applied code generation in .NET
NetWork - 15.10.2011 - Applied code generation in .NET
 
Spring
SpringSpring
Spring
 
Model-driven and low-code development for event-based systems | Bobby Calderw...
Model-driven and low-code development for event-based systems | Bobby Calderw...Model-driven and low-code development for event-based systems | Bobby Calderw...
Model-driven and low-code development for event-based systems | Bobby Calderw...
 
My cool new Slideshow!
My cool new Slideshow!My cool new Slideshow!
My cool new Slideshow!
 
Rebooting design in RavenDB
Rebooting design in RavenDBRebooting design in RavenDB
Rebooting design in RavenDB
 

Más de ciconf

CICONF 2012 - Don't Make Me Read Your Mind
CICONF 2012 - Don't Make Me Read Your MindCICONF 2012 - Don't Make Me Read Your Mind
CICONF 2012 - Don't Make Me Read Your Mindciconf
 
Chef + AWS + CodeIgniter
Chef + AWS + CodeIgniterChef + AWS + CodeIgniter
Chef + AWS + CodeIgniterciconf
 
Work Queues
Work QueuesWork Queues
Work Queuesciconf
 
Pretty Good Practices/Productivity
Pretty Good Practices/ProductivityPretty Good Practices/Productivity
Pretty Good Practices/Productivityciconf
 
Who Needs Ruby When You've Got CodeIgniter
Who Needs Ruby When You've Got CodeIgniterWho Needs Ruby When You've Got CodeIgniter
Who Needs Ruby When You've Got CodeIgniterciconf
 
Hosting as a Framework
Hosting as a FrameworkHosting as a Framework
Hosting as a Frameworkciconf
 
Zero to Hero in Start-ups
Zero to Hero in Start-upsZero to Hero in Start-ups
Zero to Hero in Start-upsciconf
 

Más de ciconf (7)

CICONF 2012 - Don't Make Me Read Your Mind
CICONF 2012 - Don't Make Me Read Your MindCICONF 2012 - Don't Make Me Read Your Mind
CICONF 2012 - Don't Make Me Read Your Mind
 
Chef + AWS + CodeIgniter
Chef + AWS + CodeIgniterChef + AWS + CodeIgniter
Chef + AWS + CodeIgniter
 
Work Queues
Work QueuesWork Queues
Work Queues
 
Pretty Good Practices/Productivity
Pretty Good Practices/ProductivityPretty Good Practices/Productivity
Pretty Good Practices/Productivity
 
Who Needs Ruby When You've Got CodeIgniter
Who Needs Ruby When You've Got CodeIgniterWho Needs Ruby When You've Got CodeIgniter
Who Needs Ruby When You've Got CodeIgniter
 
Hosting as a Framework
Hosting as a FrameworkHosting as a Framework
Hosting as a Framework
 
Zero to Hero in Start-ups
Zero to Hero in Start-upsZero to Hero in Start-ups
Zero to Hero in Start-ups
 

Último

The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 

Último (20)

The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 

How to use ORM

  • 1. To use an ORM or not to use an ORM? Harro Verton @ CICONF 2012, London, UK
  • 2. Who is this guy? • Digitally known as WanWizard • Partner in Exite, an ICT company in the Netherlands • Runs Exite’s Development and Hosting business • In software development for over 30 years • Loves writing code whenever time permits • DataMapper ORM • Modular CI • FuelPHP Core developer • Hates being reminded of his age! © Harro Verton, Exite BV, 2012
  • 3. So, what is an ORM? • Object Relational Mapping • Programming technique to map scalar data into objects with full knowledge of their relationship with other objects Object Object Object Object  Martin Fowler, Patterns of Enterprise Application Architecture © Harro Verton, Exite BV, 2012
  • 4. Architectural design patterns Active Record pattern Data Mapper pattern • Other patterns exist, but are not widely used • Table Data Gateway  basic singleton model per table • Row Data Gateway  separates table and row singletons © Harro Verton, Exite BV, 2012
  • 5. Active Record pattern • A design pattern where an object is represented as a record on a table in a relational database • Very efficient due to the assumption “1 object = 1 record” • Relationship from object  database • Configuration driven, not schema dependent • Code and data in a single object • Very fast if implemented properly • Used by most ORM implementations • CodeIgniter’s Active Record is NOT an Active Record pattern, it’s a Query Builder! © Harro Verton, Exite BV, 2012
  • 6. Data Mapper pattern • A design pattern where an object represents a data collection • More flexible, a collection can be anything • Mapping code is separated from data • Relationship from datastore  object • Complexity and flexibility comes at a cost • Less efficient  more overhead  slower • Not very widely used © Harro Verton, Exite BV, 2012
  • 7. Related patterns • Unit of Work pattern • Maintains a list of objects affected by a business transaction and coordinates the writing out of changes and the resolution of concurrency problems. • Identity Map pattern • Ensures that each object gets loaded only once by keeping every loaded object in a map. Looks up objects using the map when referring to them. • Lazy Load pattern • An object that doesn't contain all of the data you need but knows how to get it. • Most ORM implementations can't be bothered!  Matt Zandstra, PHP Objects, Patterns and Practice, 3rd edition © Harro Verton, Exite BV, 2012
  • 8. Are you still with me? Good! © Harro Verton, Exite BV, 2012
  • 9. OK. Now why would you use an ORM? • Object oriented access to your data • Unified access to your data • Abstracting the underlying storage mechanism • Both for the storage platform and the data access language • Abstracting complexity of data manipulation • Reduces the time to develop an application • Easier and faster application maintenance © Harro Verton, Exite BV, 2012
  • 10. And why should you not? • Every abstraction layer adds processing time • Lots of objects  lots of memory needed • Generated queries can be sub-optimal • An ORM can not generate all queries possible • Some ORM’s duplicate the database layer • Some ORM’s don’t save you much development time due to their complex implementation © Harro Verton, Exite BV, 2012
  • 11. Work around the issues • Lots of objects  lots of memory needed • Think carefully about what you fetch • Use standard DB calls when manipulating large volumes • Generated queries can be sub-optimal, or • An ORM can not generate all queries possible • Determine if this really is a problem for your application • Some ORM’s allow custom SQL • Fall back to standard DB calls as a last resort • Some ORM’s don’t save you much development time due to their complex implementation. • Ask yourself: did I make the correct choice? © Harro Verton, Exite BV, 2012
  • 12. It also depends on your situation • Your time is free, and no money for servers?  Code low-level, every CPU cycle counts! • Your code has to be maintained by others?  Using an ORM is probably a good idea  You’re working in a team, and time == money?  ORM is the way to go, and use separate models too!  The message here is:  CPU Power is cheap  Good developers are expensive  Spend money where it counts! © Harro Verton, Exite BV, 2012
  • 13. Good. No more theory. Awake again? © Harro Verton, Exite BV, 2012
  • 14. Using an ORM in an MVC framework Database Request Models ORM Layer Controller Response Views • The ORM is your data abstraction layer • The Model contains your business logic • What not to do:  have the business logic in the controller and use the ORM as your model  Some ORM’s allow you to merge the functionality of the Model and the ORM  but think carefully about the complexity… © Harro Verton, Exite BV, 2012
  • 15. Some ORM’s that can be used with CI • Active Record based • Datamapper ORM (http://datamapper.wanwizard.eu) • Propel (http://www.propelorm.org) • NitroORM (http://nitro-orm.net) • PHP ActiveRecord (http://www.phpactiverecord.org) • GAS ORM (http://gasorm-doc.taufanaditya.com) • Ignited Record (http://www.assembla.com/spaces/IgnitedRecord/wiki) • Data Mapper based • Doctrine (http://www.doctrine-project.org) • There are more… © Harro Verton, Exite BV, 2012
  • 16. Datamapper ORM • Pro’s: • Around for a very long time ( < 2008 ) • Very stable and full-featured API • Fully integrated into CI • Con’s: • Code base has aged due to CI’s PHP4 support • Implemented as a Model base class © Harro Verton, Exite BV, 2012
  • 17. Propel • Pro’s: • Around even longer ( since 2005 ) • Very rich feature set • Con’s: • Has it’s own database layer • Uses XML schema’s to generate the model code • Requires command-line access © Harro Verton, Exite BV, 2012
  • 18. NitroORM • Pro’s: • Very promising feature roadmap • Con’s: • Very new ( 7 months ), not mature • Lots of features still missing • No visible activity after the last release ( 11/2011 ) • Requires PHP 5.3+ ( note that CI only requires 5.1.6+ )  Your host might not support it! • Documentation is very sparse © Harro Verton, Exite BV, 2012
  • 19. PHP ActiveRecord • Pro’s: • Complete feature set, including validation • CI integration available ( how-to or using a spark ) • Con’s: • No visible activity: • Last stable release almost 2 years old • Last nightly build 5 months old © Harro Verton, Exite BV, 2012
  • 20. GAS ORM • Pro’s: • Fully integrated into CI • Built-in query caching • Con’s: • Only a few months old, no roadmap known • Not a lot of documentation available © Harro Verton, Exite BV, 2012
  • 21. Ignited Record • Pro’s: • Eh... • Con’s: • No visible activity since 2008 • Compatible with CI 2.x? • Consider this one dead and buried… © Harro Verton, Exite BV, 2012
  • 22. Doctrine • Pro’s: • Full featured, implements the full “Fowler stack” • Con’s: • Uses a command line interface • Very complex to work with • No query methods, the DQL must be used © Harro Verton, Exite BV, 2012
  • 23. Considerations when making a choice • Does my project benefit from using an ORM? • Which pattern am I going to use? • Does it have all functionality my project requires? • How about support and documentation? • Other considerations: • How easy is the integration into CodeIgniter? • Do they provide CodeIgniter support? • How large is the user base? • Is it still actively maintained? • Is their code stable enough to invest time in? • Check the CI forums for possible issues! © Harro Verton, Exite BV, 2012
  • 24. Question Time ! © Harro Verton, Exite BV, 2012
  • 25. Thank you for attending! • Tomorrow: • Masterclass on Datamapper ORM • Download the files from the programme page on the website • More questions? • Find me here today or tomorrow • Use the CodeIgniter forums • Twitter: @WanWizard • Email: codeigniter@wanwizard.eu © Harro Verton, Exite BV, 2012