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

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

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

CrystalのFramework Amberの紹介

Masayuki Uchida

June 21, 2018
Tweet

More Decks by Masayuki Uchida

Other Decks in Technology

Transcript

  1. 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
  2. 03.(SBOJUF class Post < Granite::Base adapter mysql field name :

    String field body : String timestamps end
  3. (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
  4. 3FMBUJPOTIJQ class User < Granite::Base adapter mysql has_many :posts field

    email : String field name : String timestamps end
  5. .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
  6. .JDSBUF w CJONJDSBUF #! /usr/bin/env crystal # Require your database's

    adapter # require "pg" # require "mysql" # require "sqlite3" require "micrate" Micrate::Cli.run
  7. .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
  8. .JDSBUF w NJDSBUFVQ -- +micrate Up CREATE TABLE users(id INT

    PRIMARY KEY, email VARCHAR NOT NULL); -- +micrate Down DROP TABLE users;
  9. ͦͷଞಛघͳػೳ 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