SlideShare a Scribd company logo
1 of 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

More Related Content

Viewers also liked

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
 

Viewers also liked (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 to 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 to 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
 

More from 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
 

More from 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
 

Recently uploaded

Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
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
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
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
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 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