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

Crystalに再びRailsの夢を見る Amber編

Crystalに再びRailsの夢を見る Amber編

CrystalのFramework Amberの紹介

A6618ec50149a809bcef17a5512b4448?s=128

Masayuki Uchida

June 21, 2018
Tweet

Transcript

  1. $SZTUBMʹ࠶ͼ 3BJMTͷເΛݟΔ "NCFSฤ .BTBZVLJ6DIJB!NTLZ ౦ژ$SZTUBMษڧձ

  2. UXJUUFS!NTLZ HJUIVC!NTLZ

  3. $SZTUBMษڧձ IUUQTXXXTMJEFTIBSFOFUFUNOLDSZTUBMSBJMT

  4. w ͜ͷࠒݟ͍ͯͨເ w 'SPTU w ΍͸Γॳظͷഁյతมߋʹ߅͑ͳ͍ w ݱࡏͷόʔδϣϯͰ͸ϏϧυΛ௨͢ͷ΋ࠔ೉

  5. "NCFS IUUQTBNCFSGSBNFXPSLPSH

  6. (FUUJOH4UBSUFEʹै͏ w CSFXJOTUBMMBNCFS w $SZTUBM͸YYܥ͕͋Δલఏ  w BNCFSOFXpSTUBNCFSENZTRMUFDS w E%#ࢦఆʢσϑΥϧτ͸1PTUHSF42-ʣ

    w UςϯϓϨʔτࢦఆʢσϑΥϧτ͸TMBOHʣ
  7. (FUUJOH4UBSUFEଓ͖ w DEpSTUBNCFS w TIBSETJOTUBMM w BNCFSHTDB⒎PME"SUJDMFUJUMFTUSJOHDPOUFOUTUSJOH w BNCFSECDSFBUFNJHSBUF w

    BNCFSXBUDI
  8. ೝূͷྫ w BNCFSHBVUI6TFS w BNCFSECNJHSBUF

  9. 3PVUFS "NCFS4FSWFSDPOpHVSFEPcBQQc SPVUFTXFCEP HFUQSPpMF 6TFS$POUSPMMFS TIPX HFUQSPpMFFEJU 6TFS$POUSPMMFS FEJU QBUDIQSPpMF

    6TFS$POUSPMMFS VQEBUF HFUTJHOJO 4FTTJPO$POUSPMMFS OFX QPTUTFTTJPO 4FTTJPO$POUSPMMFS DSFBUF HFUTJHOPVU 4FTTJPO$POUSPMMFS EFMFUF HFUTJHOVQ 3FHJTUSBUJPO$POUSPMMFS OFX QPTUSFHJTUSBUJPO 3FHJTUSBUJPO$POUSPMMFS DSFBUF SFTPVSDFTQFUT 1FU$POUSPMMFS HFU )PNF$POUSPMMFS JOEFY FOE FOE
  10. 03.(SBOJUF class Post < Granite::Base adapter mysql field name :

    String field body : String timestamps end
  11. (SBOJUFଓ͖ w OBNFE5VQMF1PTUOFX OBNF/BNF CPEZ*BNUIF CPEZz  w IBTI1PTUOFX \OBNF/BNF

    CPEZ*BNUIF CPEZ^UP@I  w GSPN+TPO1PTUGSPN@KTPO +40/QBSTF  \OBNF/BNF  CPEZ*BNUIFCPEZz^ BT 1PTU  w KTPO"SSBZ1PTUGSPN@KTPO +40/QBSTF  <\OBNF 1PTU CPEZ*BNUIFCPEZGPSQPTU^ \OBNF1PTU  CPEZ*BNUIFCPEZGPSQPTU^> BT "SSBZ 1PTU
  12. 3FMBUJPOTIJQ class User < Granite::Base adapter mysql has_many :posts field

    email : String field name : String timestamps end
  13. 3FMBUJPOTIJQ class Post < Granite::Base adapter mysql belongs_to :user field

    title : String timestamps end
  14. .BOZUPNBOZ class User < Granite::Base has_many :participants field name :

    String end class Participant < Granite::Base belongs_to :user belongs_to :room end class Room < Granite::Base has_many :participants field name : String end
  15. .JHSBUJPO w IUUQTHJUIVCDPNBNCFSGSBNFXPSLNJDSBUF dependencies: micrate: github: amberframework/micrate

  16. .JDSBUF w CJONJDSBUF #! /usr/bin/env crystal # Require your database's

    adapter # require "pg" # require "mysql" # require "sqlite3" require "micrate" Micrate::Cli.run
  17. .JDSBUF w &Y NJDSBUFDSFBUFBEE@VTFST@UBCMF -- +micrate Up -- SQL in

    section 'Up' is executed when this migration is applied -- +micrate Down -- SQL section 'Down' is executed when this migration is rolled back
  18. .JDSBUF w NJDSBUFVQ -- +micrate Up CREATE TABLE users(id INT

    PRIMARY KEY, email VARCHAR NOT NULL); -- +micrate Down DROP TABLE users;
  19. ͦͷଞಛघͳػೳ w 3FDJQFT w "NCFSOFXͰग़ྗ͢ΔςϯϓϨʔτΛΧελϜઃఆ ͨ͠΋ͷ w IUUQTHJUIVCDPNBNCFSGSBNFXPSLSFDJQFT

  20. ͦͷଞಛघͳػೳ w 1JQFMJOFT w ֤63-ຖʹ)UUQͷϋϯυϥΛઃఆͰ͖Δ Amber::Server.configure do |app| pipeline :web

    do # Plug is the method to use connect a pipe (middleware) # A plug accepts an instance of HTTP::Handler # plug Amber::Pipe::Params.new plug Amber::Pipe::Logger.new plug Amber::Pipe::Flash.new plug Amber::Pipe::Session.new plug Amber::Pipe::CSRF.new end
  21. ࡶײ w ૝૾Ҏ্ʹଟػೳ w TQFDͰṖͷΤϥʔ w ΤϥʔνΣοΫͷՕॴΛߦίϝϯτΞ΢τͨ͠Βಈ͍ ͨͷͰΤϥʔνΣοΫͷͱ͜Ζʹ໰୊͋Γʁ w BVUIͷଟॏઃఆͰΤϥʔ

    w Ͳ͏͍͏ಈ͖͕ظ଴௨Γͳͷ͔͸ٞ࿦ͷඞཁ͋Γ
  22. ·ͱΊ w ͜Ε͸ߦ͚Δ͔΋͠Εͳ͍ʂ w όάΛݟ͚ͭͨΒԶ͕௚͢ɺͷؾ࣋ͪʢ࠶