Upgrade to Pro — share decks privately, control downloads, hide ads and more …

The underground in ActiveRecord::ConnectionAdap...

The underground in ActiveRecord::ConnectionAdapters

沖縄Ruby会議02
http://ruby.okinawa/okrk02/

Koichi ITO

March 10, 2018
Tweet

More Decks by Koichi ITO

Other Decks in Programming

Transcript

  1. w EBUBCBTFZNM΁ͷࢦఆBEBQUFS ΛݩʹΞμϓλΛSFRVJSF͢Δ "3$POOFDUJPO"EBQUFST
 $POOFDUJPO4QFDJpDBUJPOTQFD path_to_adapter = "active_record/connection_adapters/#{spec[:adapter]}_adapter" begin require

    path_to_adapter rescue LoadError => e (snip) end (snip) adapter_method = "#{spec[:adapter]}_connection" IUUQTHJUIVCDPNSBJMTSBJMTCMPCWSDBDUJWFSFDPSEMJCBDUJWF@SFDPSEDPOOFDUJPO@BEBQUFSTDPOOFDUJPO@TQFDJpDBUJPOSC-- SFRVJSF
  2. w EBUBCBTFZNM΁ͷࢦఆBEBQUFS ΛݩʹίωΫγϣϯϝιου໊Λܾఆ "3$POOFDUJPO"EBQUFST
 $POOFDUJPO4QFDJpDBUJPOTQFD path_to_adapter = "active_record/connection_adapters/#{spec[:adapter]}_adapter" begin require

    path_to_adapter rescue LoadError => e (snip) end (snip) adapter_method = "#{spec[:adapter]}_connection" IUUQTHJUIVCDPNSBJMTSBJMTCMPCWSDBDUJWFSFDPSEMJCBDUJWF@SFDPSEDPOOFDUJPO@BEBQUFSTDPOOFDUJPO@TQFDJpDBUJPOSC-- @DPOOFDUJPO
  3. w 3VCZΦϒδΣΫτܦ༝Ͱ.Z42-Λૢ࡞͢Δ ΫϥΠΞϯτͱͳΔυϥΠό(FN require "mysql2" client = Mysql2::Client.new( :host =>

    "localhost", :username => "root" ) results = client.query( "SELECT * FROM users WHERE group=‘githubbers'" ) results.each do |row| puts row["id"] # row[“id”].is_a? Integer if row["dne"] # non-existant hash entry is nil puts row["dne"] end end .ZTRMHFN IUUQTHJUIVCDPNCSJBONBSJPNZTRMVTBHF
  4. "3ϞσϧͱυϥΠόͷதؒ૚ $POOFDUJPO"EBQUFST "CTUSBDU"EBQUFS $POOFDUJPO "EBQUFST-BZFS "3.PEFM -BZFS %BUBCBTF $MJFOU-BZFS ˞ਤྫ͸.Z42-Ξμϓλ

    (FNpMFʹࢦఆ ͍ͯ͠Δͷ͸͜Ε $POOFDUJPO"EBQUFST "CTUSBDU.ZTRM"EBQUFS $POOFDUJPO"EBQUFST .ZTRM"EBQUFS HFN NZTRM .Z42- %BUBCBTF -BZFS "3
  5. "3ϞσϧͱυϥΠόͷதؒ૚ $POOFDUJPO "EBQUFST-BZFS "3.PEFM -BZFS %BUBCBTF $MJFOU-BZFS ˞ਤྫ͸1PTUHSF42-Ξμϓλ (FNpMFʹࢦఆ ͍ͯ͠Δͷ͸͜Ε

    $POOFDUJPO"EBQUFST 1PTUHSF42-"EBQUFS HFN QH 1PTUHSF42- %BUBCBTF -BZFS $POOFDUJPO"EBQUFST "CTUSBDU"EBQUFS "3
  6. "3ϞσϧͱυϥΠόͷதؒ૚ $POOFDUJPO "EBQUFST-BZFS "3.PEFM -BZFS %BUBCBTF $MJFOU-BZFS ˞ਤྫ͸42-JUFΞμϓλ (FNpMFʹࢦఆ ͍ͯ͠Δͷ͸͜Ε

    $POOFDUJPO"EBQUFST 42-JUF"EBQUFS HFN TRMJUF 42-JUF %BUBCBTF -BZFS $POOFDUJPO"EBQUFST "CTUSBDU"EBQUFS "3
  7. w 3BJMTຊମʹόϯυϧ͞Ε͍ͯΔίΞ ΞμϓλҎ֎΋͜͜ͰSFRVJSFͯ͠Δ "3$POOFDUJPO"EBQUFST
 $POOFDUJPO4QFDJpDBUJPOTQFD path_to_adapter = "active_record/connection_adapters/#{spec[:adapter]}_adapter" begin require

    path_to_adapter rescue LoadError => e (snip) end (snip) adapter_method = "#{spec[:adapter]}_connection" IUUQTHJUIVCDPNSBJMTSBJMTCMPCWSDBDUJWFSFDPSEMJCBDUJWF@SFDPSEDPOOFDUJPO@BEBQUFSTDPOOFDUJPO@TQFDJpDBUJPOSC-- SFRVJSF ࠶ܝ
  8. 0$*$POOFDUJPO .3* $POOFDUJPO "EBQUFST-BZFS "3.PEFM -BZFS %BUBCBTF $MJFOU-BZFS ˞ਤྫ͸0SBDMFFOIBODFE 0SBDMF&OIBODFE

    0$*$POOFDJUPO Ͱܨ͍͛ͯΔ $POOFDUJPO"EBQUFST 0SBDMF&OIBODFE"EBQUFS 0SBDMF %BUBCBTF -BZFS (FNpMFʹࢦఆ ͍ͯ͠Δͷ͸͜Ε HFN SVCZPDJ $POOFDUJPO"EBQUFST "CTUSBDU"EBQUFS "3
  9. +%#$$POOFDUJPO +3VCZ $POOFDUJPO "EBQUFST-BZFS "3.PEFM -BZFS %BUBCBTF $MJFOU-BZFS ˞ਤྫ͸0SBDMFFOIBODFE 0SBDMF&OIBODFE

    +%#$$POOFDJUPO Ͱܨ͍͛ͯΔ $POOFDUJPO"EBQUFST 0SBDMF&OIBODFE"EBQUFS 0SBDMF %BUBCBTF -BZFS $-"441"5)ʹ +"3Λࢦఆ KBS PKECDKBS $POOFDUJPO"EBQUFST "CTUSBDU"EBQUFS "3