SlideShare une entreprise Scribd logo
1  sur  38
Databases - Have it
                              your way
                                Frederick Cheung - kgb



                                fred@texperts.com
                            http://www.spacevatican.org


Friday, 4 December 2009                                   1
kgb

      • Operates a number of Directory Enquiry type
              products in several countries
      • Runs the 542542 ‘Ask Us Anything’ SMS service in
              the US
      • 542542 backend is handled by several Rails apps

Friday, 4 December 2009                                    2
Whats the difference between 1080i and 1080p?
                                   kgb

      • Operates a number of Directory Enquiry type
              products in several countries
      • Runs the 542542 ‘Ask Us Anything’ SMS service in
              the US
      • 542542 backend is handled by several Rails apps

Friday, 4 December 2009                                       2
Whats the difference between 1080i and 1080p?
                                   kgb
   What is the address for the sperm bank of Pittsburgh?

      • Operates a number of Directory Enquiry type
              products in several countries
      • Runs the 542542 ‘Ask Us Anything’ SMS service in
              the US
      • 542542 backend is handled by several Rails apps

Friday, 4 December 2009                                       2
Whats the difference between 1080i and 1080p?
                                   kgb
   What is the address for the sperm bank of Pittsburgh?

      • Operates a number of Directory Enquiry type
              products in several countries
   • Runs the Greyhound bus station in Rochester, NY?
  Where is
           the 542542 ‘Ask Us Anything’ SMS service in
              the US
      • 542542 backend is handled by several Rails apps

Friday, 4 December 2009                                       2
Whats the difference between 1080i and 1080p?
                                   kgb
   What is the address for the sperm bank of Pittsburgh?

      • Operates a number of Directory Enquiry type
              products in several countries
   • Runs the Greyhound bus station in Rochester, NY?
  Where is
           the 542542 ‘Ask Us Anything’ SMS service in
              the US
      • 542542 backend is handled by several Rails apps
                                    Is marijuana legal in Oregon?


Friday, 4 December 2009                                             2
Whats the difference between 1080i and 1080p?
                                   kgb
   What is the address for the sperm bank of Pittsburgh?

      • Operates a number of Directory Enquiry type
              products in several countries
   • Runs the Greyhound bus station in Rochester, NY?
  Where is
           the 542542 ‘Ask Us Anything’ SMS service in
              the US
      • 542542 backend is handled by several Rails apps
                                    Is marijuana legal in Oregon?

 What is the longest life span of a dog in recorded history?
Friday, 4 December 2009                                             2
ORMs

                    • Hide the gunk that map objects to database
                          storage
                    • Eliminate a lot of the repetitive code
                    • don’t forget about not relational storage
                          (eg CouchDB)



Friday, 4 December 2009                                            3
Active Record within
                                  Rails
                    • redirect_to @person
                    • form_for @person
                    • rake tasks for migrations
                    • automatically configured on app load

Friday, 4 December 2009                                     4
What ORM
                             agnosticism isn’t

                    • gsub(‘ActiveRecord’, ‘DataMapper’)
                    • Not trying to make all ORM libraries look
                          the same




Friday, 4 December 2009                                           5
What ORM
                             agnosticism isn’t

                    • gsub(‘ActiveRecord’, ‘DataMapper’)
                    • Not trying to make all ORM libraries look
                          the same




Friday, 4 December 2009                                           5
Then what is it?

                    • Document / codify interactions between
                          persistence layer and rest of Rails
                    • Grease the wheels
                    • Don’t make you feel like a second class
                          citizen
                    • Should be almost invisible to end user -
                          things should just work


Friday, 4 December 2009                                          6
Choose your ORM on its features
 without worrying about bumps in
            the road



Friday, 4 December 2009        7
Patterns
                    • Active Record: “An object that wraps a
                          row in a database table or view,
                          encapsulates the database access, and adds
                          domain logic on that data.” (Martin Fowler)
                    • Data Mapper: “A layer of Mappers hat
                          moves data between objects and a database
                          while keeping them independent of each
                          other and the mapper itself.” (Martin
                          Fowler)


Friday, 4 December 2009                                                 8
Some ORMs, side by
                                side

                           Active Record, DataMapper, Sequel




Friday, 4 December 2009                                        9
Similar features across
                           the board
                    • User.new(params[:user])
                    • Associations, scopes, migrations etc.
                    • Watch out for subtle differences!



Friday, 4 December 2009                                       10
Similar features across
                           the board
                    • User.new(params[:user])
                    • Associations, scopes, migrations etc.
                    • Watch out for subtle differences!
                    #Active Record
                    person.save! #=> raises if invalid
                    person.save #=> returns false if invalid

                    #Sequel
                    person.save #=> raises if invalid
                    person.save! #=> save ignoring validations



Friday, 4 December 2009                                          10
Active Record

                    • You all know it
                    • Does a lot of manipulation of SQL
                          fragments - very difficult to build an Active
                          Record adapter for non sql datasource
                    • SQL fragments make some things easy,
                          others awkward



Friday, 4 December 2009                                                  11
Active Record Evolution

                    • In the beginning conditions were strings:
                          composing sets of conditions: yuck!
                    • hash conditions for equality & ranges
                    • named_scope
                    • and ...

Friday, 4 December 2009                                           12
Arel - Relation Algebra
      • generates db queries
      • Destined to underpin future version Active Record
      • Operations all closed under composition
       posts = Table(:posts)

       posts.where(posts[:subject].eq('Bacon'))

       posts.join(comments).on(posts[:id].eq(comments[:post_id]))




Friday, 4 December 2009                                             13
DataMapper
    • Query objects: lazy loaded definition of a query
    • Easy to compose queries
    • Easy construction of complicated joins
    • Modular design
  all_posts = Post.all

  about_test = all_posts.all :subject.like => '%test%'

  with_comment_by_fred = about_test.all Post.comments.name => 'fred'



Friday, 4 December 2009                                                14
A DM using Model
              • mappy feel to it
              • explicit about attributes (versus checking schema)
                 class Post
                   include DataMapper::Resource
                   include DataMapper::Timestamps
                   property :id, Serial
                   property :subject, String, :nullable => false
                   property :body, Text, :nullable => false
                   property :created_at, DateTime, :nullable => false
                   property :updated_at, DateTime, :nullable => false

                   has n, :comments
                 end

Friday, 4 December 2009                                                 15
Laziness
                    • attributes can be lazy loaded
                    • loads lazy loaded attributes in one query
                          for all results in collection
                    • property groups when defining laziness
                    • same strategy for loading associations
           Post.get 1
           => #<Post @id=1 @subject="Hello world" @body=<not loaded> >




Friday, 4 December 2009                                                  16
Laziness
                    • attributes can be lazy loaded
                    • loads lazy loaded attributes in one query
                          for all results in collection
                    • property groups when defining laziness
                    • same strategy for loading associations
           Post.get 1
           => #<Post @id=1 @subject="Hello world" @body=<not loaded> >




Friday, 4 December 2009                                                  16
Sequel
       • Database toolkit            - A ruby DSL for databases
                  DB[:posts].filter { created_at > Date::today - 1}.all


       • ORM layer (Migrations, associations etc. - the usual)
       • Master/Slave databases, sharding
       • pure ruby DSL for conditions
       • Mosts things are Datasets
Friday, 4 December 2009                                                   17
Sequel Model
                          class Post < Sequel::Model
                            plugin :timestamps
                            one_to_many :comments
                          end



      • comments_dataset
      • loads of customisation for eager loads
      • inverse associations
      • flexible - join on non standard columns
Friday, 4 December 2009                                18
Very modular




Friday, 4 December 2009                  19
Very modular
     Some high level




Friday, 4 December 2009                  19
Very modular
     Some high level
                    Identity map
                    Lazy attributes
                    Callbacks
                    Single/Class Table inheritance




Friday, 4 December 2009                              19
Very modular
     Some high level
                    Identity map
                    Lazy attributes
                    Callbacks
                    Single/Class Table inheritance
      Some quite grungy



Friday, 4 December 2009                              19
Very modular
     Some high level
                    Identity map
                    Lazy attributes
                    Callbacks
                    Single/Class Table inheritance
      Some quite grungy
                    Boolean readers
                    Association proxies
Friday, 4 December 2009                              19
Monolithic vs Modular
                    • Active Record in theory modular, but no
                          easy way to choose
                    • DM explicitly modular: plugins implement
                          validations, migrations, ...
                    • Sequel::Model entirely plugin driven
                    • Modularity great when you know what
                          you’re doing, but ...
                    • Tyranny of choice?
Friday, 4 December 2009                                          20
Conditions
   #Active Record
   Post.all :conditions => ["subject like ?", "%bacon%"]
   Post.all :conditions => {:approved => true}
   Post.all :conditions => ["comments.name like ?", "%bacon%"],
             :joins => :comments, :select => "distinct posts.*"

   #DataMapper
   Post.all :subject.like => '%bacon%'
   Post.all Post.comments.name.like => '%fred%'

   #Sequel
   Post.filter {subject.like '%test%'}.all
   Post.select('distinct posts.*').inner_join(:comments, :post_id
   => :id).filter {comments__name.like '%test%'}.all




Friday, 4 December 2009                                             21
More Finders
     #Active Record
     Post.find :all, :include => :comments, :order => 'created_at
     desc'

     #DataMapper

     Post.all :order => [:created_at.desc]

     #Sequel

     Post.eager(:comments).order(:created_at.desc).all
     Post.eager_graph(:comments).order('posts.created_at desc').all




Friday, 4 December 2009                                               22
You can use these
                                 today
                    • You can already build apps with other data
                          stores
                    • You can use some of the niceties like
                          redirect_to @person
                    • You need to figure out dependencies
                          between Action Pack and Active Record
                    • Compatibility worries
Friday, 4 December 2009                                            23
Little niggles


                    • Action summary doesn’t count time in DM/
                          Sequel as database time
                    • Some manual setup
                    • have to define to_param


Friday, 4 December 2009                                          24
Code time!




Friday, 4 December 2009                25
That’s all folks!

                              fred@texperts.com
                          http://www.spacevatican.org




Friday, 4 December 2009                                 26

Contenu connexe

Similaire à Databases -- Have it Your Way (Frederick Cheung)

Non Relational Databases And World Domination
Non Relational Databases And World DominationNon Relational Databases And World Domination
Non Relational Databases And World DominationJason Davies
 
Hadoop: A Hands-on Introduction
Hadoop: A Hands-on IntroductionHadoop: A Hands-on Introduction
Hadoop: A Hands-on IntroductionClaudio Martella
 
Rails ORM De-mystifying Active Record has_many
Rails ORM De-mystifying Active Record has_manyRails ORM De-mystifying Active Record has_many
Rails ORM De-mystifying Active Record has_manyBlazing Cloud
 
Scaling the Brandwatch Search Index - A History (Tim Owen at Big Data Brighton)
Scaling the Brandwatch Search Index - A History (Tim Owen at Big Data Brighton)Scaling the Brandwatch Search Index - A History (Tim Owen at Big Data Brighton)
Scaling the Brandwatch Search Index - A History (Tim Owen at Big Data Brighton)Brandwatch
 
Building A Scalable Open Source Storage Solution
Building A Scalable Open Source Storage SolutionBuilding A Scalable Open Source Storage Solution
Building A Scalable Open Source Storage SolutionPhil Cryer
 
MiningTheSocialWeb.Ch2.Microformat
MiningTheSocialWeb.Ch2.MicroformatMiningTheSocialWeb.Ch2.Microformat
MiningTheSocialWeb.Ch2.MicroformatHyeonSeok Choi
 
Rake: Not Your Father's Build Tool
Rake: Not Your Father's Build ToolRake: Not Your Father's Build Tool
Rake: Not Your Father's Build Toolfilmprog
 
Empowering the Social Web with Apache Shindig
Empowering the Social Web with Apache ShindigEmpowering the Social Web with Apache Shindig
Empowering the Social Web with Apache Shindigplindner
 
Drupal and the rise of the documents
Drupal and the rise of the documentsDrupal and the rise of the documents
Drupal and the rise of the documentsClaudio Beatrice
 
Searching and Querying Knowledge Graphs with Solr/SIREn - A Reference Archite...
Searching and Querying Knowledge Graphs with Solr/SIREn - A Reference Archite...Searching and Querying Knowledge Graphs with Solr/SIREn - A Reference Archite...
Searching and Querying Knowledge Graphs with Solr/SIREn - A Reference Archite...Lucidworks
 
Distributed Data processing in a Cloud
Distributed Data processing in a CloudDistributed Data processing in a Cloud
Distributed Data processing in a Cloudelliando dias
 
Optiq: A dynamic data management framework
Optiq: A dynamic data management frameworkOptiq: A dynamic data management framework
Optiq: A dynamic data management frameworkJulian Hyde
 
Introduction to Object-Relational Mapping
Introduction to Object-Relational MappingIntroduction to Object-Relational Mapping
Introduction to Object-Relational MappingAli Shakiba
 
Why we love ArangoDB. The hunt for the right NosQL Database
Why we love ArangoDB. The hunt for the right NosQL DatabaseWhy we love ArangoDB. The hunt for the right NosQL Database
Why we love ArangoDB. The hunt for the right NosQL DatabaseAndreas Jung
 

Similaire à Databases -- Have it Your Way (Frederick Cheung) (20)

Non Relational Databases And World Domination
Non Relational Databases And World DominationNon Relational Databases And World Domination
Non Relational Databases And World Domination
 
Infinispan for Dummies
Infinispan for DummiesInfinispan for Dummies
Infinispan for Dummies
 
Stardog talk-dc-march-17
Stardog talk-dc-march-17Stardog talk-dc-march-17
Stardog talk-dc-march-17
 
Hadoop: A Hands-on Introduction
Hadoop: A Hands-on IntroductionHadoop: A Hands-on Introduction
Hadoop: A Hands-on Introduction
 
Rails ORM De-mystifying Active Record has_many
Rails ORM De-mystifying Active Record has_manyRails ORM De-mystifying Active Record has_many
Rails ORM De-mystifying Active Record has_many
 
Scaling the Brandwatch Search Index - A History (Tim Owen at Big Data Brighton)
Scaling the Brandwatch Search Index - A History (Tim Owen at Big Data Brighton)Scaling the Brandwatch Search Index - A History (Tim Owen at Big Data Brighton)
Scaling the Brandwatch Search Index - A History (Tim Owen at Big Data Brighton)
 
Building A Scalable Open Source Storage Solution
Building A Scalable Open Source Storage SolutionBuilding A Scalable Open Source Storage Solution
Building A Scalable Open Source Storage Solution
 
MiningTheSocialWeb.Ch2.Microformat
MiningTheSocialWeb.Ch2.MicroformatMiningTheSocialWeb.Ch2.Microformat
MiningTheSocialWeb.Ch2.Microformat
 
Rake: Not Your Father's Build Tool
Rake: Not Your Father's Build ToolRake: Not Your Father's Build Tool
Rake: Not Your Father's Build Tool
 
Qcon talk
Qcon talkQcon talk
Qcon talk
 
Empowering the Social Web with Apache Shindig
Empowering the Social Web with Apache ShindigEmpowering the Social Web with Apache Shindig
Empowering the Social Web with Apache Shindig
 
Drupal and the rise of the documents
Drupal and the rise of the documentsDrupal and the rise of the documents
Drupal and the rise of the documents
 
Searching and Querying Knowledge Graphs with Solr/SIREn - A Reference Archite...
Searching and Querying Knowledge Graphs with Solr/SIREn - A Reference Archite...Searching and Querying Knowledge Graphs with Solr/SIREn - A Reference Archite...
Searching and Querying Knowledge Graphs with Solr/SIREn - A Reference Archite...
 
Forget The ORM!
Forget The ORM!Forget The ORM!
Forget The ORM!
 
Real Estate Apps and Tools
Real Estate Apps and ToolsReal Estate Apps and Tools
Real Estate Apps and Tools
 
Distributed Data processing in a Cloud
Distributed Data processing in a CloudDistributed Data processing in a Cloud
Distributed Data processing in a Cloud
 
Optiq: A dynamic data management framework
Optiq: A dynamic data management frameworkOptiq: A dynamic data management framework
Optiq: A dynamic data management framework
 
Everyday - mongodb
Everyday - mongodbEveryday - mongodb
Everyday - mongodb
 
Introduction to Object-Relational Mapping
Introduction to Object-Relational MappingIntroduction to Object-Relational Mapping
Introduction to Object-Relational Mapping
 
Why we love ArangoDB. The hunt for the right NosQL Database
Why we love ArangoDB. The hunt for the right NosQL DatabaseWhy we love ArangoDB. The hunt for the right NosQL Database
Why we love ArangoDB. The hunt for the right NosQL Database
 

Plus de Skills Matter

5 things cucumber is bad at by Richard Lawrence
5 things cucumber is bad at by Richard Lawrence5 things cucumber is bad at by Richard Lawrence
5 things cucumber is bad at by Richard LawrenceSkills Matter
 
Patterns for slick database applications
Patterns for slick database applicationsPatterns for slick database applications
Patterns for slick database applicationsSkills Matter
 
Scala e xchange 2013 haoyi li on metascala a tiny diy jvm
Scala e xchange 2013 haoyi li on metascala a tiny diy jvmScala e xchange 2013 haoyi li on metascala a tiny diy jvm
Scala e xchange 2013 haoyi li on metascala a tiny diy jvmSkills Matter
 
Oscar reiken jr on our success at manheim
Oscar reiken jr on our success at manheimOscar reiken jr on our success at manheim
Oscar reiken jr on our success at manheimSkills Matter
 
Progressive f# tutorials nyc dmitry mozorov & jack pappas on code quotations ...
Progressive f# tutorials nyc dmitry mozorov & jack pappas on code quotations ...Progressive f# tutorials nyc dmitry mozorov & jack pappas on code quotations ...
Progressive f# tutorials nyc dmitry mozorov & jack pappas on code quotations ...Skills Matter
 
Cukeup nyc ian dees on elixir, erlang, and cucumberl
Cukeup nyc ian dees on elixir, erlang, and cucumberlCukeup nyc ian dees on elixir, erlang, and cucumberl
Cukeup nyc ian dees on elixir, erlang, and cucumberlSkills Matter
 
Cukeup nyc peter bell on getting started with cucumber.js
Cukeup nyc peter bell on getting started with cucumber.jsCukeup nyc peter bell on getting started with cucumber.js
Cukeup nyc peter bell on getting started with cucumber.jsSkills Matter
 
Agile testing & bdd e xchange nyc 2013 jeffrey davidson & lav pathak & sam ho...
Agile testing & bdd e xchange nyc 2013 jeffrey davidson & lav pathak & sam ho...Agile testing & bdd e xchange nyc 2013 jeffrey davidson & lav pathak & sam ho...
Agile testing & bdd e xchange nyc 2013 jeffrey davidson & lav pathak & sam ho...Skills Matter
 
Progressive f# tutorials nyc rachel reese & phil trelford on try f# from zero...
Progressive f# tutorials nyc rachel reese & phil trelford on try f# from zero...Progressive f# tutorials nyc rachel reese & phil trelford on try f# from zero...
Progressive f# tutorials nyc rachel reese & phil trelford on try f# from zero...Skills Matter
 
Progressive f# tutorials nyc don syme on keynote f# in the open source world
Progressive f# tutorials nyc don syme on keynote f# in the open source worldProgressive f# tutorials nyc don syme on keynote f# in the open source world
Progressive f# tutorials nyc don syme on keynote f# in the open source worldSkills Matter
 
Agile testing & bdd e xchange nyc 2013 gojko adzic on bond villain guide to s...
Agile testing & bdd e xchange nyc 2013 gojko adzic on bond villain guide to s...Agile testing & bdd e xchange nyc 2013 gojko adzic on bond villain guide to s...
Agile testing & bdd e xchange nyc 2013 gojko adzic on bond villain guide to s...Skills Matter
 
Dmitry mozorov on code quotations code as-data for f#
Dmitry mozorov on code quotations code as-data for f#Dmitry mozorov on code quotations code as-data for f#
Dmitry mozorov on code quotations code as-data for f#Skills Matter
 
A poet's guide_to_acceptance_testing
A poet's guide_to_acceptance_testingA poet's guide_to_acceptance_testing
A poet's guide_to_acceptance_testingSkills Matter
 
Russ miles-cloudfoundry-deep-dive
Russ miles-cloudfoundry-deep-diveRuss miles-cloudfoundry-deep-dive
Russ miles-cloudfoundry-deep-diveSkills Matter
 
Simon Peyton Jones: Managing parallelism
Simon Peyton Jones: Managing parallelismSimon Peyton Jones: Managing parallelism
Simon Peyton Jones: Managing parallelismSkills Matter
 
I went to_a_communications_workshop_and_they_t
I went to_a_communications_workshop_and_they_tI went to_a_communications_workshop_and_they_t
I went to_a_communications_workshop_and_they_tSkills Matter
 

Plus de Skills Matter (20)

5 things cucumber is bad at by Richard Lawrence
5 things cucumber is bad at by Richard Lawrence5 things cucumber is bad at by Richard Lawrence
5 things cucumber is bad at by Richard Lawrence
 
Patterns for slick database applications
Patterns for slick database applicationsPatterns for slick database applications
Patterns for slick database applications
 
Scala e xchange 2013 haoyi li on metascala a tiny diy jvm
Scala e xchange 2013 haoyi li on metascala a tiny diy jvmScala e xchange 2013 haoyi li on metascala a tiny diy jvm
Scala e xchange 2013 haoyi li on metascala a tiny diy jvm
 
Oscar reiken jr on our success at manheim
Oscar reiken jr on our success at manheimOscar reiken jr on our success at manheim
Oscar reiken jr on our success at manheim
 
Progressive f# tutorials nyc dmitry mozorov & jack pappas on code quotations ...
Progressive f# tutorials nyc dmitry mozorov & jack pappas on code quotations ...Progressive f# tutorials nyc dmitry mozorov & jack pappas on code quotations ...
Progressive f# tutorials nyc dmitry mozorov & jack pappas on code quotations ...
 
Cukeup nyc ian dees on elixir, erlang, and cucumberl
Cukeup nyc ian dees on elixir, erlang, and cucumberlCukeup nyc ian dees on elixir, erlang, and cucumberl
Cukeup nyc ian dees on elixir, erlang, and cucumberl
 
Cukeup nyc peter bell on getting started with cucumber.js
Cukeup nyc peter bell on getting started with cucumber.jsCukeup nyc peter bell on getting started with cucumber.js
Cukeup nyc peter bell on getting started with cucumber.js
 
Agile testing & bdd e xchange nyc 2013 jeffrey davidson & lav pathak & sam ho...
Agile testing & bdd e xchange nyc 2013 jeffrey davidson & lav pathak & sam ho...Agile testing & bdd e xchange nyc 2013 jeffrey davidson & lav pathak & sam ho...
Agile testing & bdd e xchange nyc 2013 jeffrey davidson & lav pathak & sam ho...
 
Progressive f# tutorials nyc rachel reese & phil trelford on try f# from zero...
Progressive f# tutorials nyc rachel reese & phil trelford on try f# from zero...Progressive f# tutorials nyc rachel reese & phil trelford on try f# from zero...
Progressive f# tutorials nyc rachel reese & phil trelford on try f# from zero...
 
Progressive f# tutorials nyc don syme on keynote f# in the open source world
Progressive f# tutorials nyc don syme on keynote f# in the open source worldProgressive f# tutorials nyc don syme on keynote f# in the open source world
Progressive f# tutorials nyc don syme on keynote f# in the open source world
 
Agile testing & bdd e xchange nyc 2013 gojko adzic on bond villain guide to s...
Agile testing & bdd e xchange nyc 2013 gojko adzic on bond villain guide to s...Agile testing & bdd e xchange nyc 2013 gojko adzic on bond villain guide to s...
Agile testing & bdd e xchange nyc 2013 gojko adzic on bond villain guide to s...
 
Dmitry mozorov on code quotations code as-data for f#
Dmitry mozorov on code quotations code as-data for f#Dmitry mozorov on code quotations code as-data for f#
Dmitry mozorov on code quotations code as-data for f#
 
A poet's guide_to_acceptance_testing
A poet's guide_to_acceptance_testingA poet's guide_to_acceptance_testing
A poet's guide_to_acceptance_testing
 
Russ miles-cloudfoundry-deep-dive
Russ miles-cloudfoundry-deep-diveRuss miles-cloudfoundry-deep-dive
Russ miles-cloudfoundry-deep-dive
 
Serendipity-neo4j
Serendipity-neo4jSerendipity-neo4j
Serendipity-neo4j
 
Simon Peyton Jones: Managing parallelism
Simon Peyton Jones: Managing parallelismSimon Peyton Jones: Managing parallelism
Simon Peyton Jones: Managing parallelism
 
Plug 20110217
Plug   20110217Plug   20110217
Plug 20110217
 
Lug presentation
Lug presentationLug presentation
Lug presentation
 
I went to_a_communications_workshop_and_they_t
I went to_a_communications_workshop_and_they_tI went to_a_communications_workshop_and_they_t
I went to_a_communications_workshop_and_they_t
 
Plug saiku
Plug   saikuPlug   saiku
Plug saiku
 

Dernier

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
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 AutomationSafe Software
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 

Dernier (20)

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
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
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 

Databases -- Have it Your Way (Frederick Cheung)

  • 1. Databases - Have it your way Frederick Cheung - kgb fred@texperts.com http://www.spacevatican.org Friday, 4 December 2009 1
  • 2. kgb • Operates a number of Directory Enquiry type products in several countries • Runs the 542542 ‘Ask Us Anything’ SMS service in the US • 542542 backend is handled by several Rails apps Friday, 4 December 2009 2
  • 3. Whats the difference between 1080i and 1080p? kgb • Operates a number of Directory Enquiry type products in several countries • Runs the 542542 ‘Ask Us Anything’ SMS service in the US • 542542 backend is handled by several Rails apps Friday, 4 December 2009 2
  • 4. Whats the difference between 1080i and 1080p? kgb What is the address for the sperm bank of Pittsburgh? • Operates a number of Directory Enquiry type products in several countries • Runs the 542542 ‘Ask Us Anything’ SMS service in the US • 542542 backend is handled by several Rails apps Friday, 4 December 2009 2
  • 5. Whats the difference between 1080i and 1080p? kgb What is the address for the sperm bank of Pittsburgh? • Operates a number of Directory Enquiry type products in several countries • Runs the Greyhound bus station in Rochester, NY? Where is the 542542 ‘Ask Us Anything’ SMS service in the US • 542542 backend is handled by several Rails apps Friday, 4 December 2009 2
  • 6. Whats the difference between 1080i and 1080p? kgb What is the address for the sperm bank of Pittsburgh? • Operates a number of Directory Enquiry type products in several countries • Runs the Greyhound bus station in Rochester, NY? Where is the 542542 ‘Ask Us Anything’ SMS service in the US • 542542 backend is handled by several Rails apps Is marijuana legal in Oregon? Friday, 4 December 2009 2
  • 7. Whats the difference between 1080i and 1080p? kgb What is the address for the sperm bank of Pittsburgh? • Operates a number of Directory Enquiry type products in several countries • Runs the Greyhound bus station in Rochester, NY? Where is the 542542 ‘Ask Us Anything’ SMS service in the US • 542542 backend is handled by several Rails apps Is marijuana legal in Oregon? What is the longest life span of a dog in recorded history? Friday, 4 December 2009 2
  • 8. ORMs • Hide the gunk that map objects to database storage • Eliminate a lot of the repetitive code • don’t forget about not relational storage (eg CouchDB) Friday, 4 December 2009 3
  • 9. Active Record within Rails • redirect_to @person • form_for @person • rake tasks for migrations • automatically configured on app load Friday, 4 December 2009 4
  • 10. What ORM agnosticism isn’t • gsub(‘ActiveRecord’, ‘DataMapper’) • Not trying to make all ORM libraries look the same Friday, 4 December 2009 5
  • 11. What ORM agnosticism isn’t • gsub(‘ActiveRecord’, ‘DataMapper’) • Not trying to make all ORM libraries look the same Friday, 4 December 2009 5
  • 12. Then what is it? • Document / codify interactions between persistence layer and rest of Rails • Grease the wheels • Don’t make you feel like a second class citizen • Should be almost invisible to end user - things should just work Friday, 4 December 2009 6
  • 13. Choose your ORM on its features without worrying about bumps in the road Friday, 4 December 2009 7
  • 14. Patterns • Active Record: “An object that wraps a row in a database table or view, encapsulates the database access, and adds domain logic on that data.” (Martin Fowler) • Data Mapper: “A layer of Mappers hat moves data between objects and a database while keeping them independent of each other and the mapper itself.” (Martin Fowler) Friday, 4 December 2009 8
  • 15. Some ORMs, side by side Active Record, DataMapper, Sequel Friday, 4 December 2009 9
  • 16. Similar features across the board • User.new(params[:user]) • Associations, scopes, migrations etc. • Watch out for subtle differences! Friday, 4 December 2009 10
  • 17. Similar features across the board • User.new(params[:user]) • Associations, scopes, migrations etc. • Watch out for subtle differences! #Active Record person.save! #=> raises if invalid person.save #=> returns false if invalid #Sequel person.save #=> raises if invalid person.save! #=> save ignoring validations Friday, 4 December 2009 10
  • 18. Active Record • You all know it • Does a lot of manipulation of SQL fragments - very difficult to build an Active Record adapter for non sql datasource • SQL fragments make some things easy, others awkward Friday, 4 December 2009 11
  • 19. Active Record Evolution • In the beginning conditions were strings: composing sets of conditions: yuck! • hash conditions for equality & ranges • named_scope • and ... Friday, 4 December 2009 12
  • 20. Arel - Relation Algebra • generates db queries • Destined to underpin future version Active Record • Operations all closed under composition posts = Table(:posts) posts.where(posts[:subject].eq('Bacon')) posts.join(comments).on(posts[:id].eq(comments[:post_id])) Friday, 4 December 2009 13
  • 21. DataMapper • Query objects: lazy loaded definition of a query • Easy to compose queries • Easy construction of complicated joins • Modular design all_posts = Post.all about_test = all_posts.all :subject.like => '%test%' with_comment_by_fred = about_test.all Post.comments.name => 'fred' Friday, 4 December 2009 14
  • 22. A DM using Model • mappy feel to it • explicit about attributes (versus checking schema) class Post include DataMapper::Resource include DataMapper::Timestamps property :id, Serial property :subject, String, :nullable => false property :body, Text, :nullable => false property :created_at, DateTime, :nullable => false property :updated_at, DateTime, :nullable => false has n, :comments end Friday, 4 December 2009 15
  • 23. Laziness • attributes can be lazy loaded • loads lazy loaded attributes in one query for all results in collection • property groups when defining laziness • same strategy for loading associations Post.get 1 => #<Post @id=1 @subject="Hello world" @body=<not loaded> > Friday, 4 December 2009 16
  • 24. Laziness • attributes can be lazy loaded • loads lazy loaded attributes in one query for all results in collection • property groups when defining laziness • same strategy for loading associations Post.get 1 => #<Post @id=1 @subject="Hello world" @body=<not loaded> > Friday, 4 December 2009 16
  • 25. Sequel • Database toolkit - A ruby DSL for databases DB[:posts].filter { created_at > Date::today - 1}.all • ORM layer (Migrations, associations etc. - the usual) • Master/Slave databases, sharding • pure ruby DSL for conditions • Mosts things are Datasets Friday, 4 December 2009 17
  • 26. Sequel Model class Post < Sequel::Model plugin :timestamps one_to_many :comments end • comments_dataset • loads of customisation for eager loads • inverse associations • flexible - join on non standard columns Friday, 4 December 2009 18
  • 27. Very modular Friday, 4 December 2009 19
  • 28. Very modular Some high level Friday, 4 December 2009 19
  • 29. Very modular Some high level Identity map Lazy attributes Callbacks Single/Class Table inheritance Friday, 4 December 2009 19
  • 30. Very modular Some high level Identity map Lazy attributes Callbacks Single/Class Table inheritance Some quite grungy Friday, 4 December 2009 19
  • 31. Very modular Some high level Identity map Lazy attributes Callbacks Single/Class Table inheritance Some quite grungy Boolean readers Association proxies Friday, 4 December 2009 19
  • 32. Monolithic vs Modular • Active Record in theory modular, but no easy way to choose • DM explicitly modular: plugins implement validations, migrations, ... • Sequel::Model entirely plugin driven • Modularity great when you know what you’re doing, but ... • Tyranny of choice? Friday, 4 December 2009 20
  • 33. Conditions #Active Record Post.all :conditions => ["subject like ?", "%bacon%"] Post.all :conditions => {:approved => true} Post.all :conditions => ["comments.name like ?", "%bacon%"], :joins => :comments, :select => "distinct posts.*" #DataMapper Post.all :subject.like => '%bacon%' Post.all Post.comments.name.like => '%fred%' #Sequel Post.filter {subject.like '%test%'}.all Post.select('distinct posts.*').inner_join(:comments, :post_id => :id).filter {comments__name.like '%test%'}.all Friday, 4 December 2009 21
  • 34. More Finders #Active Record Post.find :all, :include => :comments, :order => 'created_at desc' #DataMapper Post.all :order => [:created_at.desc] #Sequel Post.eager(:comments).order(:created_at.desc).all Post.eager_graph(:comments).order('posts.created_at desc').all Friday, 4 December 2009 22
  • 35. You can use these today • You can already build apps with other data stores • You can use some of the niceties like redirect_to @person • You need to figure out dependencies between Action Pack and Active Record • Compatibility worries Friday, 4 December 2009 23
  • 36. Little niggles • Action summary doesn’t count time in DM/ Sequel as database time • Some manual setup • have to define to_param Friday, 4 December 2009 24
  • 37. Code time! Friday, 4 December 2009 25
  • 38. That’s all folks! fred@texperts.com http://www.spacevatican.org Friday, 4 December 2009 26