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

ORM使いたい、あと伝えたいこと

 ORM使いたい、あと伝えたいこと

社内向け説明資料

threetreeslight

October 03, 2013
Tweet

More Decks by threetreeslight

Other Decks in Technology

Transcript

  1. ORMÍàÍÇ ÏàÍÖç   2013/10/3  

  2. „ƒç~¡ÙåqÙÍ   „ƒ       ORMāÍàÍ     Þëàõêö~¡ÙåòÙÍ

          WebăĨijďĹēıĸëĕďĹIJĥijĜĄāäàõêìRESTfullçÍΓ Ï`Ò9     RESTfullé“Ï`ìĉħĔćčĞZ.ëMVCĦĵĹĬķĹčç…NÒ˜Í     MVCĦĵĹĬķĹč췂&|Ò˜Í     ĉħĔćčĞZ.MVCëModel³ ìÇORMāÎ緂Òn   Ļű!æéÍçÖÿø¸°ãåÍýçÖÿöhüóÛÒǞ®ÙåØÍļ  
  3. Web  Applica�onæ9 éÖç     ĕďĹIJĥijĜĄ:     – ÍãîÍăčĖĕÙåÓåö9:ĺ  

    ĻÛ×ÍđĹģĹāÎ`uāºÔļ     &|:   – ·‚ÒbÍĺĭĸĜĠĸĕÒnĺ   Ļ ]ā4øÛçÍÎ`uāºÔļ  
  4. Sec�on:  ĕďĹIJĥijĜĄ     ĹÆÍãîÍăčĖĕÙåÓåö9:ĺÆĹ  

  5. Ques�on:  èÎøãåÊÍãîÍăčĖĕÙåÓåö9:Ëêł   Answer:  đĹģĹæëmāwûÞÎĺ     đĹģĹæëmë#wìÇREST(Representa�onal  State  Transfer)

     é“Ï` ĻRESTfullļā±€Ûþí>}æÓóÛÈ   1.  ĕĜĹĞĵĕ(State  less)éčIJąăĸĞ/đĹģĨĶĞĐĴ   2.  ÛñåëQ3Â(ijėĹĕ)  ê±€æÓýÊúÔ=‘Øþà\ËëĖĚĞ   3.  ijėĹĕāRê¨"ÛýÊr€ƒéo^Ë   4.  ăĨijďĹēıĸëQ3ç{S²‰ë`āWÎÖçÒæÓýÊĢąĤĹĭ ĝĄăë€Ë  
  6. R/Ò ÑûéÍçMÎëæÇ   ää¦cÙóÛÈ  

  7. Ques�on:ÆRESTëĕĜĹĞĵĕãåł   Answer:  Æ{SĻstateļāYÙéÍĻlessļ æÛ   ĕĜĹĞĦĴéĢĸģĹċĹēıĚĨçĕĜĹĞĵĕéĢĸģĹċĹēıĚĨāê ¦cÙóÛÈ  

  8. ŀÆĕĜĹĞÊĦĴËéĢĸģĹċĹēıĚĨ ĕĘĚĦ   ?A   v^èÎéØÍóÛÑł   ?AæÛÈĢĸģĹċĹØÍ   ĩĜĞìèÎéØÍóÛÑł

      ÀôzìèÎéØþóÛÑł   ĩĜĞöØÍÈ   ĐĹIJÔáØÍÈ   ³æľĿĽêéüóÛÈ  
  9.   ĕĘĚĦĻđĹģĹļÒ   ?ĻčIJąăĸĞļë{Sā   ¢TÛýLÒÌý     äóüÇÍãîÍ?Òjýç0 ¢TÛýLÒÌýëæÇĕďĹĴÒ1

    ½ÈĻŁPÙÍÑéÇ}™ëăĨijďĹēıĸë{tļ   ĕĜĹĞÊĦĴËéĢĸģĹċĹēıĚĨìÇ  
  10. ŀÆĕĜĹĞÊĵĕËéĢĸģĹċĹēıĚĨ   ĕĘĚĦ   ?   v^èÎéØÍóÛÑł   ?AæÛÈĢĸģĹċĹØÍ  

    ĩĜĞìèÎéØÍóÛÑł   ÀôzìèÎéØþóÛÑł   ?AæÛÈĢĸģĹċĹçĩĜĞØÍ   ?AæÛÈĢĸģĹċĹçĩĜĞçĐĹIJÔáØÍÈ   ³æľĿĽêéüóÛÈ  
  11. ĕĜĹĞÊĵĕËéĢĸģĹċĹēıĚĨìÇ     ĕĘĚĦĻđĹģĹļÒ   ?ĻčIJąăĸĞļë{Sā   ¢TÛýLÒyÍ    

    äóüÇÍãîÍ?ÒÓåö¢TÛýLÒyÍëæÇĕďĹĴÒ@dÈ ĻijhýñÓ;ļ  
  12. Ques�on:ÆèÎøãåĕĜĹĞĵĕā>}ÛýëÑł   Answer:  ÆURI  (  URL  )āÏíjóÛÈ      

    ôĂéúԞýĐąěæÛÈ h�p://weather.yahoo.co.jp/weather/jp/13/4410.html       RESTëÊijėĹĕāRê¨"Ûýr€ƒéo^Ëê…FÙóÛÈ    
  13. ŀÆĢĸģĹċĹēıĚĨëURI     ĕĘĚĦĻđĹģĹļðëv^   –  ?ŀÆ?A   –  ĭąĸĭġįĹŀÆĢĸģĹċĹ

      –  đħĭġįĹŀÆĩĜĞ   –  ğijĸčŀÆĐĹIJ     h�p://macdnald.com/client/a/orders/new/main/burger/sub/potato/drink/coke   ÐD   ?A   ĢĸģĹċĹ   ĩĜĞ   ĐĹIJ   ăčēıĸ  
  14. ŀÆĢĸģĹċĹēıĚĨëURI   ?ë™'ÛñåāURIæšÛçÏíÇÇÇ     v^   h�p://macdnald.com/client/a/orders/new/main/burger/sub/potato/drink/coke    

    v^@ë­%   h�p://macdnald.com/client/a/add_order/1/sub/cheese     v^ëČĮĸĖĴ   h�p://macdnald.com/client/a/delete_order/1     v^ë   h�p://macdnald.com/client/a/orders     v^륏   h�p://macdnald.com/client/a/orders/1  
  15. ÖþæĕĜĹĞĵĕÒ>}æÓýÒÇÇÇ   1.  v^øv^@ā­%ÛýURIÒy¹ê¶ÔéýëÒ«Í   h�p://macdnald.com/client/a/orders/new/main/burger/sub/potato/drink/coke   2.  ĕĘĚĦÒ¸°Ïåv^­%Ùâ÷ãàüÇaêČĮĸĖĴÙàv^āE ČĮĸĖĴÙúÎçÙå¬ĀéÍÑł

      Ļ,ÚURIêăčĖĕÙåÇâ÷Ăç,Ú{SÒXĻ‹NļØþýëÑļ   h�p://macdnald.com/client/a/delete_order/1         éèÇ?ĻđĹĥĕļöĕĘĚĦĻđĹģĹļöK´ Ò8ÍÈ     ĐĐ   ĐĐ  
  16. Ques�on:ÆèÎøãå?çĕĘĚĦëK´ ā¡sÛýëÑł Answer:  ÆøüàÍ ê+ãàHTTPĭėĚğāÎç<ĺ     RESTëÊÛñåëQ3Â(ijėĹĕ)  ê±€æÓýúÔ=‘Øþà\ëĖĚĞËê… FÙóÛÈ

        ÞþæìòèëĢĸģĹċĹēıĚĨëURIæ¦cÙóÛÈ  
  17. ŀÆøüàÍ çHTTPĭėĚğëĪĚĨ HTTPĭ ĭė ėĚ Ěğ ğ   ? ?ë

    ë' '    DBë ë\ \  (CRUD)   , ,Ú Ú{ {S Së ë   X X Ļ Ļ ‹ ‹N Nļ ļ   POST   v^ë­%   CREATE   yÙ   GET   v^@ë)J   v^ ë)J   READ   hü   PUT/PATCH   v^@ëf_   UPDATE   ³Çhü   Ļf_A© 7êG ¾āÏéÍàõļ   DELETE   v^ëČĮĸĖĴ   DELETE   hü  
  18. ŀÆ>»ëURL     ĉĹęĹë   h�p://macdnald.com/client/a/orders       ĉĹęĹë­%

      h�p://macdnald.com/client/a/orders/new       ĉĹęĹ륏   h�p://macdnald.com/client/a/orders/4123       ĉĹęĹë6f   h�p://macdnald.com/client/a/orders/4123       ĉĹęĹëČĮĸĖĴ   h�p://macdnald.com/client/a/orders/4123     POST   GET   DELETE   GET   PUT   HTTP  method   URL  
  19. ĕďĹIJĥijĜĄëóçõ     ĕďĹIJĥijĜĄā>}ÛýàõêìRESTfullêÙú Îĺ     RESTfullì ë@ā±!ê>›ÙúÎĺ  

    –  ĕĜĹĞĵĕêÛýÈ   –  ĕĜĹĞĵĕêÛýêìÇURIê{SāYàÝúÎÈ   –  URIā<êWÎêìÇøüàÍ ç +ãàHTTPĭėĚğ āÐÎ  
  20. Sec�on:  &|     ĹÆ·‚ÒbÍĺĭĸĜĠĸĕÒnÂĹ  

  21. &|ë˜Íweb  applica�on·‚   1.  G¾Œ2Ò ÑüøÛÍ   –  ĨĶĎIJĬ,5ҁ+(  loose

     coupling)æÌýÈ     MVC  framework  !!!   1.  §ÒžåöáÍàÍêÒhýëÑÒ~¡æÓýÈ   –  ĨĶĎIJĬëH$ĻDBçëøüçüÇHTMLëUļÒc†ê Ñþå ÍýÈ   MVC  framework  !!!    
  22. MVCĦĵĹĬķĹčìˆ  

  23. MVCăĨijďĹēıĸë   čIJąăĸĞ   1.  HTTPijčĈĕĞ     (URI,  HTTPĭėĚğ)

      Rou�ng  /     Dispatcher   Controller   DB   Model   2.  URIçĭėĚğë¡k   View   3.  ăčēıĸĻ~ļëZ=   5.  DBðë~   ĻCRUDļ   8.  İĹĒŚ‡HTMLāU   4   6   7   9   10.HTTPĵĕĩĸĕ   Applica�on  
  24. ÖþìRESTfulléđĹĥĕêö ïãàüĺ     áÕèÈÈÈ  

  25. >}êÐÍå½ÙÍĩąĸĞ   DB   Model   5.  DBðë~   ĻCRUDļ

        RDBçĻObjectZ.ëļMVCìÇʅNÒOÍËÈ           liƒé“Ï`Ò°ÎàõǂÙåÍýÈ   –  RDBìÇÃàáëĻĕĊIJĹļÄ   –  ObjectìÇÃ[ý—ÍĻĭėĚğļçCNĻĭĸģļÄ  
  26. ÞÖæORM    (Object-­‐rela�onal  mapping)     *ÉëĜĹħĴāÞþßþClassçÙåWÎÈ     ĜĹħĴëĊIJĬìǤFÛýčIJĕëCNĻĭĸģļçÙåWÎÈ

        ĜĹħĴðë\ìUserModelÑû™ÎÈ   Class  User  extends  Model  {   }     User  Table   =   Class  User  extends  Model  {    protected  name   }   User  Table   -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐   Name  |  varchar(256)   =   $user  =  User::find_by_id(3000);   $user.name  //=  akira   SELECT  *  FROM  user     WHERE  id  =  3000;     //  id                |  name   //  -­‐-­‐-­‐-­‐          |-­‐-­‐-­‐-­‐-­‐   //    3000  |  akira   =  
  27. BÙÜäçÑÙåÍÓóÙùÎĺ  

  28. gIêÇĨĶĎIJīĸĎāÛýàõëKoÏ   ĻçÍÎ-ëпÍļ     CoC:  conven�on  over  configura�on  

    –  Ÿì·‚”ës=ÛñÓÖçĻ£=ļāwBØÝÇ(ŽêÛý     DRY:  Don’t  Repeat  Yourself   –  Q3뵜ì6fë1½Øā49Ù¯cNāwBØÝÇ–āÚý   ĻvRŀ  No  Once  and  Only  One(  OAOO  )  ļ     KISS:  Keep  it  Simple,  Stupid   –  ėĦĞĆćăҜ¼êéýêäþåÇÍ`ā’JÛýe¸Ò4ÏàüÇ\êV¸ )ãàüÇèþÒµép•éëÑ ÑûéÔéýÈ     YAGNI:  You  ain’t  gonna  need  it   –  p•ì>»êLçéýóæì­%ÙéÍëÒúÍÈÌçæÎáÿÎçëxëê ãàöëìÇ>»êì10%ŠEÙÑĀþéÍÈÙàÒãåÞþêªøÙàe¸ë 90%ìyÁêéýÈ  
  29. enjoy  cording!