SlideShare ist ein Scribd-Unternehmen logo
1 von 67
Rails and Alternative
        ORMs
       Dan Weinand
       Jonathan Dahl
Why?
DB vs. OO

declarative vs. imperative
DB vs. OO

char/text vs. string
DB vs. OO

schema vs. _______
DB vs. OO

joins vs. pointers
DB vs. OO

public vs. encapsulated
DB vs. OO

constraints vs. validation
DB vs. OO

_____ vs. inheritance
DB vs. OO

DBA vs. programmer
DB vs. OO

structure vs. behavior
http://www.engrish.com//wp-content/uploads/2008/08/hand-grenade.jpg
1. ActiveRecord
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, PoEAA, 160.
One object per row.
Data access and domain
logic are done together.
6 Criticisms
of ActiveRecord
1. Too much magic.




http://cgi.ebay.com/MEDIEVAL-MAGE-KING-BLACK-TUNIC-COSTUME-SCA-LARP-_W0QQitemZ250373576829QQcmdZViewItemQQimsxZ20090215?IMSfp=TL090215143008r8810#ebayphotohosting
class User < ActiveRecord::Base
end
2. Not performant.




 http://www.flickr.com/photos/danprates/1418154518/
3. Not thread safe.
   No connection pooling.




  http://www.flickr.com/photos/streetmuseo/57990915/
4. Hides SQL from you.




http://www.momentaryfascinations.com/entertainment/the.lost.monty.python.cartoon/still.5.jpg
5. Hard to fight against.




 http://www.mmonotebook.com/wp-content/uploads/2008/04/larp.jpg
6. Encourages stupid databases.
9 ways to bypass
application-level
   constraints
1. Fixtures
2.   Klass.delete(1)
3.   record.save(false)
4.
5. Share DB with a
    second app
6.   User.create(:company_id => 1)
class User < ActiveRecord::Base
7.     has_many :posts
     end
8. ActiveRecord::Base.connection.execute()
9. Errors in your app
        logic
2. Sequel
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, PoEAA, 160.
Ruby DSL for SQL

posts = DB[:posts]
posts.filter(:category => /ruby/i, :author => [:jon, :dan])
posts.reverse_order(:created_at, :updated_at)
posts.select(:title, :author)
posts.limit(10)
Ruby-like DSL for SQL


posts.filter(:category => :ruby).order(:created_at).select(:title, :author)
ORM
class Post < Sequel::Model
  many_to_many :tags
  many_to_one :author
  validates_presence_of :title
end

post = Post[123]
post.title # quot;rails ormsquot;
post.title = quot;Rails ORMsquot;
post.save
3 interesting things


sequel postgres://localhost:5432/myapp_development
3 interesting things
require 'memcache'
CACHE = MemCache.new 'localhost:11211', :namespace => 'blog'

class Author < Sequel::Model
  set_cache CACHE, :ttl => 3600
end

Author[333] # database hit
Author[333] # cache hit
3 interesting things

DB = Sequel.sqlite('app_test.db',

 :servers=>{:read_only=>{:host=>'slave_server'}})
3. Datamapper
A layer of Mappers (473) that moves data between objects and
a database while keeping them independent of each other and
the mapper itself.
                                    Martin Fowler, PoEAA, 165.
Multiple Databases

• SQL-based
• In-memory
• Document-based
• Search engines
Explicit property mapping
class Message
  include DataMapper::Resource

  property :name, String
  property :body, Text
  property :created_at, DateTime

  validates_presence_of :name
end
Get only the data you need
Minimize the number of
       queries
Save only the data that
     has changed
Identity Map

repository do
  @parent.children.each do |child|
    puts @parent.object_id = child.parent.object_id
  end
end
Ruby Query Syntax
Zoo.first(:name.eql => 'Galveston')

Person.all(:age.gt => 30)
Person.all(:age.gte => 30)
Person.all(:name.not => 'bob')

Person.all(:name.like => 'S%', :id => [1,2,3,4,5])

Person.all(:name.not => ['bob','rick','steve'])

Person.all(:order => [:age.desc])
Chainable finders
class Zoo
  def self.open
    all(:open => true)
  end

  def self.big
    all(:animal_count.gte => 1000)
  end
end

big_open_zoos = Zoo.big.open
Associations
class Article
  include DataMapper::Resource

  property :id, Serial
  property :title, String
  property :content, Text
  belongs_to :author
end


class Author
  include DataMapper::Resource

  property :id, Serial
  property :name, String
  has n, :articles
end

Article.all('author.name' => 'Michael')
Implicit and explicit
    migrations
Only basic functionality
       in core
Gems for everything else
Is it ready for
  primetime?
Roadmap to 1.0
Rails integration still
        lacking
Not many production
    deployments
Documentation sucks
Some plugins still not
      ported
Thanks!
Dan Weinand
  Jon Dahl

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

Zend framework 03 - singleton factory data mapper caching logging
Zend framework 03 - singleton factory data mapper caching loggingZend framework 03 - singleton factory data mapper caching logging
Zend framework 03 - singleton factory data mapper caching logging
 
Data repositories
Data repositoriesData repositories
Data repositories
 
Intro to MongoDB and datamodeling
Intro to MongoDB and datamodeling Intro to MongoDB and datamodeling
Intro to MongoDB and datamodeling
 
MVest Spring Job Execution
MVest Spring Job ExecutionMVest Spring Job Execution
MVest Spring Job Execution
 
Google Dorks
Google DorksGoogle Dorks
Google Dorks
 
Digesting jQuery
Digesting jQueryDigesting jQuery
Digesting jQuery
 
wtf is in Java/JDK/wtf7?
wtf is in Java/JDK/wtf7?wtf is in Java/JDK/wtf7?
wtf is in Java/JDK/wtf7?
 
Euruko 2009 - DataObjects
Euruko 2009 - DataObjectsEuruko 2009 - DataObjects
Euruko 2009 - DataObjects
 
MySQL User Conference 2009: Python and MySQL
MySQL User Conference 2009: Python and MySQLMySQL User Conference 2009: Python and MySQL
MySQL User Conference 2009: Python and MySQL
 
What's Parse
What's ParseWhat's Parse
What's Parse
 
Compass Framework
Compass FrameworkCompass Framework
Compass Framework
 
Scaling / optimizing search on netlog
Scaling / optimizing search on netlogScaling / optimizing search on netlog
Scaling / optimizing search on netlog
 
Schema design short
Schema design shortSchema design short
Schema design short
 
Mysql DBI
Mysql DBIMysql DBI
Mysql DBI
 
My_sql_with_php
My_sql_with_phpMy_sql_with_php
My_sql_with_php
 
What's up in ruby for Java developers
What's up in ruby for Java developersWhat's up in ruby for Java developers
What's up in ruby for Java developers
 
Mongo db
Mongo dbMongo db
Mongo db
 
Android datastorage
Android datastorageAndroid datastorage
Android datastorage
 
Quiz With Answers Drupal
Quiz With  Answers  DrupalQuiz With  Answers  Drupal
Quiz With Answers Drupal
 
Couchbase & FTS
Couchbase & FTSCouchbase & FTS
Couchbase & FTS
 

Andere mochten auch

Designing Great APIs: Learning from Jony Ive, Orwell, and the Kano Model
Designing Great APIs: Learning from Jony Ive, Orwell, and the Kano ModelDesigning Great APIs: Learning from Jony Ive, Orwell, and the Kano Model
Designing Great APIs: Learning from Jony Ive, Orwell, and the Kano ModelJonathan Dahl
 
Aristotle and the Art of Software Development (Agile 2009)
Aristotle and the Art of Software Development (Agile 2009)Aristotle and the Art of Software Development (Agile 2009)
Aristotle and the Art of Software Development (Agile 2009)Jonathan Dahl
 
Aristotle and the Art of Software Development
Aristotle and the Art of Software DevelopmentAristotle and the Art of Software Development
Aristotle and the Art of Software DevelopmentJonathan Dahl
 
Advanced API Design: how an awesome API can help you make friends, get rich, ...
Advanced API Design: how an awesome API can help you make friends, get rich, ...Advanced API Design: how an awesome API can help you make friends, get rich, ...
Advanced API Design: how an awesome API can help you make friends, get rich, ...Jonathan Dahl
 
Programming and Minimalism: Lessons from Orwell and the Clash
Programming and Minimalism: Lessons from Orwell and the ClashProgramming and Minimalism: Lessons from Orwell and the Clash
Programming and Minimalism: Lessons from Orwell and the ClashJonathan Dahl
 
Pandas Updated2
Pandas Updated2Pandas Updated2
Pandas Updated2stopxanh
 

Andere mochten auch (6)

Designing Great APIs: Learning from Jony Ive, Orwell, and the Kano Model
Designing Great APIs: Learning from Jony Ive, Orwell, and the Kano ModelDesigning Great APIs: Learning from Jony Ive, Orwell, and the Kano Model
Designing Great APIs: Learning from Jony Ive, Orwell, and the Kano Model
 
Aristotle and the Art of Software Development (Agile 2009)
Aristotle and the Art of Software Development (Agile 2009)Aristotle and the Art of Software Development (Agile 2009)
Aristotle and the Art of Software Development (Agile 2009)
 
Aristotle and the Art of Software Development
Aristotle and the Art of Software DevelopmentAristotle and the Art of Software Development
Aristotle and the Art of Software Development
 
Advanced API Design: how an awesome API can help you make friends, get rich, ...
Advanced API Design: how an awesome API can help you make friends, get rich, ...Advanced API Design: how an awesome API can help you make friends, get rich, ...
Advanced API Design: how an awesome API can help you make friends, get rich, ...
 
Programming and Minimalism: Lessons from Orwell and the Clash
Programming and Minimalism: Lessons from Orwell and the ClashProgramming and Minimalism: Lessons from Orwell and the Clash
Programming and Minimalism: Lessons from Orwell and the Clash
 
Pandas Updated2
Pandas Updated2Pandas Updated2
Pandas Updated2
 

Ähnlich wie Rails and alternative ORMs

[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVCAlive Kuo
 
Hands On Spring Data
Hands On Spring DataHands On Spring Data
Hands On Spring DataEric Bottard
 
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...SPTechCon
 
Using Document Databases with TYPO3 Flow
Using Document Databases with TYPO3 FlowUsing Document Databases with TYPO3 Flow
Using Document Databases with TYPO3 FlowKarsten Dambekalns
 
Python RESTful webservices with Python: Flask and Django solutions
Python RESTful webservices with Python: Flask and Django solutionsPython RESTful webservices with Python: Flask and Django solutions
Python RESTful webservices with Python: Flask and Django solutionsSolution4Future
 
Painless Persistence in a Disconnected World
Painless Persistence in a Disconnected WorldPainless Persistence in a Disconnected World
Painless Persistence in a Disconnected WorldChristian Melchior
 
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011Nick Sieger
 
Art of Javascript
Art of JavascriptArt of Javascript
Art of JavascriptTarek Yehia
 
SXSW 2012 JavaScript MythBusters
SXSW 2012 JavaScript MythBustersSXSW 2012 JavaScript MythBusters
SXSW 2012 JavaScript MythBustersElena-Oana Tabaranu
 
12 core technologies you should learn, love, and hate to be a 'real' technocrat
12 core technologies you should learn, love, and hate to be a 'real' technocrat12 core technologies you should learn, love, and hate to be a 'real' technocrat
12 core technologies you should learn, love, and hate to be a 'real' technocratJonathan Linowes
 
How Rackspace Cloud Monitoring uses Cassandra
How Rackspace Cloud Monitoring uses CassandraHow Rackspace Cloud Monitoring uses Cassandra
How Rackspace Cloud Monitoring uses Cassandragdusbabek
 
AJS UNIT-1 2021-converted.pdf
AJS UNIT-1 2021-converted.pdfAJS UNIT-1 2021-converted.pdf
AJS UNIT-1 2021-converted.pdfSreeVani74
 
Rapid Prototyping with Solr
Rapid Prototyping with SolrRapid Prototyping with Solr
Rapid Prototyping with SolrErik Hatcher
 
REST APIs in Laravel 101
REST APIs in Laravel 101REST APIs in Laravel 101
REST APIs in Laravel 101Samantha Geitz
 
#NoXML: Eliminating XML in Spring Projects - SpringOne 2GX 2015
#NoXML: Eliminating XML in Spring Projects - SpringOne 2GX 2015#NoXML: Eliminating XML in Spring Projects - SpringOne 2GX 2015
#NoXML: Eliminating XML in Spring Projects - SpringOne 2GX 2015Matt Raible
 

Ähnlich wie Rails and alternative ORMs (20)

[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC
 
Hands On Spring Data
Hands On Spring DataHands On Spring Data
Hands On Spring Data
 
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
 
Using Document Databases with TYPO3 Flow
Using Document Databases with TYPO3 FlowUsing Document Databases with TYPO3 Flow
Using Document Databases with TYPO3 Flow
 
Sequelize
SequelizeSequelize
Sequelize
 
Python RESTful webservices with Python: Flask and Django solutions
Python RESTful webservices with Python: Flask and Django solutionsPython RESTful webservices with Python: Flask and Django solutions
Python RESTful webservices with Python: Flask and Django solutions
 
Painless Persistence in a Disconnected World
Painless Persistence in a Disconnected WorldPainless Persistence in a Disconnected World
Painless Persistence in a Disconnected World
 
Data herding
Data herdingData herding
Data herding
 
Data herding
Data herdingData herding
Data herding
 
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
 
Art of Javascript
Art of JavascriptArt of Javascript
Art of Javascript
 
SXSW 2012 JavaScript MythBusters
SXSW 2012 JavaScript MythBustersSXSW 2012 JavaScript MythBusters
SXSW 2012 JavaScript MythBusters
 
12 core technologies you should learn, love, and hate to be a 'real' technocrat
12 core technologies you should learn, love, and hate to be a 'real' technocrat12 core technologies you should learn, love, and hate to be a 'real' technocrat
12 core technologies you should learn, love, and hate to be a 'real' technocrat
 
How Rackspace Cloud Monitoring uses Cassandra
How Rackspace Cloud Monitoring uses CassandraHow Rackspace Cloud Monitoring uses Cassandra
How Rackspace Cloud Monitoring uses Cassandra
 
AJS UNIT-1 2021-converted.pdf
AJS UNIT-1 2021-converted.pdfAJS UNIT-1 2021-converted.pdf
AJS UNIT-1 2021-converted.pdf
 
Rapid Prototyping with Solr
Rapid Prototyping with SolrRapid Prototyping with Solr
Rapid Prototyping with Solr
 
REST APIs in Laravel 101
REST APIs in Laravel 101REST APIs in Laravel 101
REST APIs in Laravel 101
 
Spring data requery
Spring data requerySpring data requery
Spring data requery
 
JDBC Part - 2
JDBC Part - 2JDBC Part - 2
JDBC Part - 2
 
#NoXML: Eliminating XML in Spring Projects - SpringOne 2GX 2015
#NoXML: Eliminating XML in Spring Projects - SpringOne 2GX 2015#NoXML: Eliminating XML in Spring Projects - SpringOne 2GX 2015
#NoXML: Eliminating XML in Spring Projects - SpringOne 2GX 2015
 

Kürzlich hochgeladen

Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
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
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
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
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
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
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
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
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 

Kürzlich hochgeladen (20)

Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
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
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
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
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
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
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
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
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 

Rails and alternative ORMs

Hinweis der Redaktion

  1. So ... Why use an ORM?
  2. Because your database and your OO code are unlike things. Different paradigms. So in a sense, any time you use a relational DB + OO, you&#x2019;re going to do some sort of object relational mapping. May be formal or informal.
  3. So data types are not identical
  4. Your DB has a formal definition independent of the use of the data.
  5. This is a big one. In OO, you follow references - an object can &#x201C;point&#x201D; to another object, and so on. In SQL, you logically join sets of data together.
  6. Any bit of data can be joined to any other bit. In OO, ideal is to hide as much as you can and only expose a public interface.
  7. declarative vs. active - declare that certain kinds of data are acceptable, vs. actively checking at certain points in time.
  8. SQL doesn&#x2019;t directly have a concept of inheritance. Fundamental to OO.
  9. Finally, different purposes. Define structure for data (and hold that data) vs. Doing something
  10. So basically, ORM are translators between unlike things. Like any translation,
  11. this isn&#x2019;t going to be perfectly smooth, and there will always be tradeoffs. In this talk, Dan and I are going to talk about these tradeoffs by looking at three approaches to ORM with Ruby.
  12. You&#x2019;re probably familiar with this already, so I won&#x2019;t show much code here or talk about how to use AR. Instead, let&#x2019;s talk for a few minutes at a more theoretical level.
  13. In this pattern, an object wraps each DB row. This single object handles both domain logic and database access. What's unique about this?
  14. Other approaches might not treat each row as an object, or might combine multiple rows into a single object.
  15. Others might separate these, filtering the data through a logic layer, instead of exposing both side-by-side.
  16. class User < ActiveRecord::Base end That does a _lot_. And from looking at this, you have no idea exactly what it did. You have to check the db schema in order to figure that out. The good news is that convention dominates. Once you know the conventions, you generally aren't surprised.
  17. This is true, by default. N+1, loads all columns, etc. It would be really nice if it could do these things. But at the same time, it provides facilities for these sorts of optimizations.
  18. This is part of the reason that alternative ORMs got started. The thing is, it isn't true any more. At least not entirely.
  19. This guy, Josh Peek, made Rails 2.2 thread safe.
  20. And this guy, who you may recognize, added the current connection pooling.
  21. The fact is, as a AR developer, you can pretty much forget how to write a join. This isn't really a limitation of AR - some could say that it&#x2019;s a feature. But at the same time, you really do need to know SQL if you&#x2019;re going to use a relational database. That said, my SQL skills have atrophied as a Rails developer. On our newest project, Luke and I have had to do quite a bit of custom SQL, and we've tried to make our DB layer a bit smarter and more robust. Which leads to the next criticism...
  22. Rails makes polymorphic associations easy and multi-table inheritance hard. But polymorphic associations: bad idea. Cuts out a join table, but hurts referential integrity. But because it&#x2019;s easy, you see a lot of it. Is this a valid criticism? It usually isn&#x2019;t that hard to fight against AR&#x2019;s conventions, and most of the time, you don&#x2019;t want to.
  23. This is bad. Basically, foreign keys require a plugin. Redhill. This plugin works, but isn't all that actively maintained, and some things (constraints) aren't even supported by that. You can always run a bare connection.execute() statement, but this won't get dumped into your schema.rb file, which is bad. According to DHH et al, you don't need DB constraints, and you want a dumb DB.
  24. 4. Access your database directly.
  25. Company 1 may not exist. Or
  26. I.e. you make a mistake
  27. I.e. you make a mistake. This probably isn&#x2019;t a problem for you, but it might be for some of the other people you work with.
  28. Sequel is a thread-safe DB library with a lightweight ORM
  29. Follows the ActiveRecord pattern
  30. So you don&#x2019;t have to write much real SQL
  31. So you don&#x2019;t have to write much real SQL
  32. The Sequel ORM is very similar to AR, at least on the surface. Does many of the things that Rails does, at least the basics.
  33. Also has similar support for sharding