The underground in ActiveRecord::ConnectionAdapters

The underground in ActiveRecord::ConnectionAdapters

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

023b04c98f39cc041293d780352432ff?s=128

Koichi ITO

March 10, 2018
Tweet

Transcript

  1. "DUJWF3FDPSE $POOFDUJPO"EBQUFST ͷԼͷੈ ք ླྀٿେֶ޻ֶ෦߸ؗ  4BU ԭೄ3VCZձٞ 5IFVOEFSHSPVOEJO"3$POOFDUJPO"EBQUFST %JWFUPUIFSBJMTSBJMTSFQPTJUPSZ

    ג Ӭ࿨γεςϜϚωδϝϯτ ҏ౻ߒҰ !LPJD
  2. None
  3. None
  4. ࠓ೔ͷ࿩

  5. None
  6. None
  7. None
  8. w %JWFUPSBJMTSBJMTSFQP w "3$POOFDUJPO"EBQUFST w 0SBDMFFOIBODFEBEBQUFS w 0SBDMFXJUI3BJMT "HFOEB ˞#BTFEPO3BJMTSD

  9. Dive to rails/rails

  10. None
  11. None
  12. None
  13. None
  14. None
  15. None
  16. AR::ConectionAdapters

  17. w "3ͷϞσϧܦ༝Ͱͷݺͼग़͠ʹର͠ ͯɺ3%#.4͝ͱʹཧʹ͔ͳͬͨ42- Λ૊Έཱͯͯฦ͢໾ׂ w 3%#.4ͷ࢓༷Λલఏ͢Δɻྫ͑͹ 0SBDMFͩͱۭจࣈͱ/6--Λ۠ผ͠ ͳ͍ɺHἬ͸ࣝผࢠ͕จࣈҎԼ "3$POOFDUJPO"EBQUFST

  18. SBJMTSBJMTͷςετͰ஌Δ3%#.4ͷ ࢓༷ʹΑΔৼΔ෣͍ͷҧ͍ DVSSFOU@BEBQUFS

  19. rails/rails#29370

  20. WTOJM

  21. Ξμϓλͷࢦఆͱ 3BJMTΛىಈ࣌ͷ ৼΔ෣͍ʹ͍ͭͯ

  22. w ͝ଘ஌EBUBCBTFZNMʹࢦఆ͢Δ BEBQUFSͱ͸Կͳͷ͔͍·Ұ౓ $POOFDUJPO"EBQUFSͷબ୒ development: adapter: mysql2 development: adapter: postgresql

    development: adapter: sqlite3 development: adapter: oracle_enhanced
  23. w EBUBCBTFZNMͰࢦఆͨ͠Ξμϓλ͕ SBJMTDSBJMTTͰཁٻ͞ΕΔἬͷྲྀΕ "33BJMUJFJOJUJBMJ[FS "3$POOFDUJPO)BOEMJOHFTUBCMJTI@DPOOFDUJ PO "3$POOFDUJPO"EBQUFST$POOFDUJPO4QFDJpD BUJPOTQFD FTUBCMJTI@DPOOFDUJPO

  24. "33BJMUJFJOJUJBMJ[FS IUUQTHJUIVCDPNSBJMTSBJMTCMPCWSDBDUJWFSFDPSEMJCBDUJWF@SFDPSESBJMUJFSC-

  25. "3$POOFDUJPO)BOEMJOH
 FTUBCMJTI@DPOOFDUJPO IUUQTHJUIVCDPNSBJMTSBJMTCMPCWSDBDUJWFSFDPSEMJCBDUJWF@SFDPSEDPOOFDUJPO@IBOEMJOHSC-

  26. "3$POOFDUJPO"EBQUFST
 $POOFDUJPO4QFDJpDBUJPOTQFD IUUQTHJUIVCDPNSBJMTSBJMTCMPCWSDBDUJWFSFDPSEMJCBDUJWF@SFDPSEDPOOFDUJPO@BEBQUFSTDPOOFDUJPO@TQFDJpDBUJPOSC-

  27. 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
  28. SFRVJSF͞ΕΔ$PSFBEBQUFST

  29. 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
  30. IUUQTHJUIVCDPNSBJMTSBJMTCMPCWSDBDUJWFSFDPSEMJCBDUJWF@SFDPSEDPOOFDUJPO@BEBQUFSTNZTRM@BEBQUFSSC- @DPOOFDUJPO

  31. IUUQTHJUIVCDPNSBJMTSBJMTCMPCWSDBDUJWFSFDPSEMJCBDUJWF@SFDPSEDPOOFDUJPO@BEBQUFSTNZTRM@BEBQUFSSC- @DPOOFDUJPO %#$MJFOU

  32. 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
  33. "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
  34. "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
  35. "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
  36. w EBUBCBTFZNMʹج͍ͮͨ $POOFDUJPO"EBQUFSTΛ࢖͏ w $POOFDUJPO"EBQUFSͷઌͷ઀ଓ ͸σʔλϕʔευϥΠόHFNͱͳΔ w NZTRM QH TRMJUFͳͲ

    "3ͷσʔλϕʔε઀ଓͷߏ଄
  37. w SBJMTSBJMTϦϙδτϦͰϝϯςφ ϯε͞Ε͍ͯΔΞμϓλΛࢦ͢ w ݱࡏ.Z42- NZTRM  1PTUHSF42-42-JUFͷͭ w 3BJMTͷ$*ϚτϦοΫεʹೖͬͯΔ

    $PSFBEBQUFST
  38. w ֎෦(FNͱͯ͠ཁٻ͞ΕΔΞμϓλ w 0SBDMF w 42-4FSWFS w 'JSFCJSE w FUD

    FUD SEQBSUZBEBQUFST
  39. 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" IUUQTHJUIVCDPNSBJM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ྫ͸0SBDMFFOIBODFE 0SBDMF&OIBODFE

    +%#$$POOFDJUPO Ͱܨ͍͛ͯΔ $POOFDUJPO"EBQUFST 0SBDMF&OIBODFE"EBQUFS 0SBDMF %BUBCBTF -BZFS $-"441"5)ʹ +"3Λࢦఆ KBS PKECDKBS $POOFDUJPO"EBQUFST "CTUSBDU"EBQUFS "3
  50. w KSVCZBDUJWFSFDPSEKECDBEBQUFS Ͱ؅ཧ͞Ε͍ͯΔ <ิ଍>0SBDMFҎ֎ͷ+%#$αϙʔτ

  51. A development of Oracle enhanced adapter

  52. w */%&9ʹؔ͢Δ5"#-&41"$&Λࢦఆ Ͱ͖ΔΑ͏ʹରԠͨ͠<> w SBJMTECTDIFNBMPBEͷϚϧνΠϯ αʔτʹରԠͨ͠<> w 3VCZ0$*Λ3VCZͷ #JH%FDJNBMରԠ<SVCZPDJ> ࢥ͍ग़ͷύονબ

  53. w */%&9ʹؔ͢Δ5"#-&41"$&Λࢦఆ Ͱ͖ΔΑ͏ʹରԠͨ͠<> w SBJMTECTDIFNBMPBEͷϚϧνΠϯ αʔτʹରԠͨ͠<> w 3VCZ0$*Λ3VCZͷ #JH%FDJNBMରԠ<SVCZPDJ> ͸͡ΊͯͷΞμϓλύον

  54. rsim/oracle-enhanced#1028

  55. w 0SBDMFͰ͸5"#-&41"$&Ͱςʔϒϧ ΍ΠϯσοΫεͷอଘྖҬࢦఆ͕Ͱ͖Δ w 0SBDMFFOBIBODFEBEBQUFSͰ͸ EFGBVMU@UBCMFTQBDFTͰࢦఆՄೳ w QSJNBSZLFZʹରͯ͠͏·͘ޮ͔ͳ ͔ͬͨͷͰ௚ͨ͠ 5"#-&41"$&ͷࢦఆ

  56. w ౰࣌ࣗ৴͕ͳ͘*TTVFͰ͓࢕͍ खݩʹϞϯΩʔύον͸͋ͬͨ

  57. w 54@*/%&9Ͱͳ͘54@%"5"ʹೖͬͯͨ ໰୊΁ͷमਖ਼ύον 0QFOB13

  58. "3.JHSBUJPOͷDSBFUF@UBCMF΁ͷ SEQBSUZΞμϓλ࣮૷΁ͷมߋ தུ ௥Ճ IUUQTHJUIVCDPNSTJNPSBDMFFOIBODFECMPCWSDMJCBDUJWF@SFDPSEDPOOFDUJPO@BEBQUFSTPSBDMF@FOIBODFETDIFNB@TUBUFNFOUTSC-

  59. w "-5&3*/%&93&#6*-%5"#-&41"$&Λ ࣮ߦ͢ΔϝιουΛఆ͍ٛͯ͠Δ ADSFBUF@UBCMFA͔ΒͷϑοΫ

  60. w ϦϙδτϦΛԣஅͨ͠มߋ͕ඞཁͩͬͨ $*͕ͱ͓Βͳ͍

  61. w 64&34Ͱͳ͘4:45&.ʹอଘ͞Εͯͨ w %&'"6-55"#-&41"$&ͷมߋ w 0SBDMF޲͚ͷSBJMTEFWCPY΁ͷ13 ZBIPOEBSBJMTEFWCPY

  62. w 3%#.4΁ͷΞμϓλ։ൃͳͷͰ 3%#.4ʹԠͨ͡։ൃ؀ڥΛ੔උ͢Δ ඞཁ͕͋Δ w ZBIPOEBSBJMTEFWCPY͕ 0SBDMF޲͚ͷ։ൃ؀ڥͱͳΔ w $*ͱ߹Θͤͯ͜ͷ؀ڥΛ࢖͏ͷ͕ྑ͍ ։ൃ؀ڥ΁ͷ஌ݟΛಘΔ

  63. Oracle with Rails 6.0

  64. w 3BJMTҎલ͸ϓϥΠϚϦΩʔ*%ͷ ࠾൪ʹ͍ͭͯ4&26&/$&Ͱ෷͍ग़͞ Ε͍ͯΔ w 3BJMTҎ߱͸0SBDMFDͷ *EFOUJUZ$PMVNOΛ࢖͏ํ਑Ͱݕ౼ w OFYUWBMͱ͍͏1P$ͷϦϒʔτ 1P$*EFOUJUZ

  65. w 3BJMTҎલͷσϑΥϧτ஋͸ EFGBVMU@TFRVFODF@TUBSU@WBMVF  w 3BJMTҎޙͷσϑΥϧτ஋͸ EFGBVMU@TFRVFODF@TUBSU@WBMVF ʹͳΓଞͷΞμϓλͱಉ͡ڍಈʹ $IBOHFAEFGBVMU@TFRVFODF@TUBSU@WBMVFA GSPNUP

  66. w SBJMTECTUSVDUVSFEVNQͷࡍ ʹσϑΥϧτͰ7*&8͕μϯϓ͞Ε ΔΑ͏ʹͳΔ &YUSBDUWJFXTUPEC TUSVDUVSFTRMCZEFGBVMU

  67. w 0SBDMF͸%"5"#"4&-*/,ͱ͍͏ ଞͷ%#ͷσʔλΛҾ͘ػߏ͕͋Γ 3BJMTܥ0SBDMFΞμϓλἬαϙʔτ w 3BJMTҎޙ͸3BJMTͷෳ਺%#ର Ԡʹ೚ͤΔ͜ͱʹͳΓػೳ࡟আ͢Δํ ਑ SBJMTSBJMT΋ࢀর %SPQEBUBCBTFMJOLTVQQPSU

  68. %SPQEBUBCBTFMJOLTVQQPSU

  69. w "3#BTFDPOOFDUJPOUBCMFTͷ ໭Γ஋ʹؚΊͯΔϚςϏϡʔΛ֎͠ςʔ ϒϧͷΈฦ͢Α͏ʹ͢Δ͔Ͳ͏͔ʁ w 1PTUHSF42-Ξμϓλʹ͓͚Δಉϝ ιου͕ϚςϏϡʔΛฦ͔͢Ͳ͏͔ʹ ΑΔ (JU)VCίϝϯτௐ΂ &YDMVEFANBUFSJBMJ[FE@WJFXTA

    GSPNAUBCMFTA
  70. w 0SBDMFD3ҎԼͰ͸ΧϥϜ໊ͳ ͲࣝผࢠʹόΠτҎԼͷ੍ݶ͕͋Δ w SBJMTSBJMTͷ"3ͷҰ෦ͷςετ͕ 0SBDMFͰམͪΔ͍ͪཁҼͰ΋͋Δ w 0SBDMFD3Ҏ্͸όΠτ ·Ͱͷ֦ு͞ΕΔ͚ͲͲ͏͢Δʁ -POHJEFOUJpFSTTVQQPSU

  71. +3VCZ +%#$TVQQPSUT0SBDMFD PSIJHIFS1%# 1MVHHBCMFEBUBCBTF

  72. Oracle enhanced 6.0 may require Oracle 12c or higher

  73. w ਓྨͰ΋ݟ͍ͯΔਓ͕ݶΒΕ͍ͯΔͱ͍͏ $POOFDUJPO"EBQUFSTͷ໾ׂͱߏ੒ͱ ϦϙδτϦͰͷ৔ॴʹ͍ͭͯ࿩͠·ͨ͠ w "SFMपล͸೉͍͠ͷͰׂѪ͍ͯ͠·͕͢ɺ ͜ͷ͋ͨΓ৮ΕΔͱ͔ͳΓڧ͍ͱࢥ͍·͢ w LBNJQP͞ΜͱZBIPOEB͞Μ͸͍͢͝ਓ ͓ΘΓʹ

  74. None