Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

UXJUUFS!NTLZ HJUIVC!NTLZ

Slide 3

Slide 3 text

$SZTUBMษڧձ IUUQTXXXTMJEFTIBSFOFUFUNOLDSZTUBMSBJMT

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

"NCFS IUUQTBNCFSGSBNFXPSLPSH

Slide 6

Slide 6 text

(FUUJOH4UBSUFEʹै͏ w CSFXJOTUBMMBNCFS w $SZTUBM͸YYܥ͕͋Δલఏ w BNCFSOFXpSTUBNCFSENZTRMUFDS w E%#ࢦఆʢσϑΥϧτ͸1PTUHSF42-ʣ w UςϯϓϨʔτࢦఆʢσϑΥϧτ͸TMBOHʣ

Slide 7

Slide 7 text

(FUUJOH4UBSUFEଓ͖ w DEpSTUBNCFS w TIBSETJOTUBMM w BNCFSHTDB⒎PME"SUJDMFUJUMFTUSJOHDPOUFOUTUSJOH w BNCFSECDSFBUFNJHSBUF w BNCFSXBUDI

Slide 8

Slide 8 text

ೝূͷྫ w BNCFSHBVUI6TFS w BNCFSECNJHSBUF

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

03.(SBOJUF class Post < Granite::Base adapter mysql field name : String field body : String timestamps end

Slide 11

Slide 11 text

(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

Slide 12

Slide 12 text

3FMBUJPOTIJQ class User < Granite::Base adapter mysql has_many :posts field email : String field name : String timestamps end

Slide 13

Slide 13 text

3FMBUJPOTIJQ class Post < Granite::Base adapter mysql belongs_to :user field title : String timestamps end

Slide 14

Slide 14 text

.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

Slide 15

Slide 15 text

.JHSBUJPO w IUUQTHJUIVCDPNBNCFSGSBNFXPSLNJDSBUF dependencies: micrate: github: amberframework/micrate

Slide 16

Slide 16 text

.JDSBUF w CJONJDSBUF #! /usr/bin/env crystal # Require your database's adapter # require "pg" # require "mysql" # require "sqlite3" require "micrate" Micrate::Cli.run

Slide 17

Slide 17 text

.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

Slide 18

Slide 18 text

.JDSBUF w NJDSBUFVQ -- +micrate Up CREATE TABLE users(id INT PRIMARY KEY, email VARCHAR NOT NULL); -- +micrate Down DROP TABLE users;

Slide 19

Slide 19 text

ͦͷଞಛघͳػೳ w 3FDJQFT w "NCFSOFXͰग़ྗ͢ΔςϯϓϨʔτΛΧελϜઃఆ ͨ͠΋ͷ w IUUQTHJUIVCDPNBNCFSGSBNFXPSLSFDJQFT

Slide 20

Slide 20 text

ͦͷଞಛघͳػೳ 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

Slide 21

Slide 21 text

ࡶײ w ૝૾Ҏ্ʹଟػೳ w TQFDͰṖͷΤϥʔ w ΤϥʔνΣοΫͷՕॴΛߦίϝϯτΞ΢τͨ͠Βಈ͍ ͨͷͰΤϥʔνΣοΫͷͱ͜Ζʹ໰୊͋Γʁ w BVUIͷଟॏઃఆͰΤϥʔ w Ͳ͏͍͏ಈ͖͕ظ଴௨Γͳͷ͔͸ٞ࿦ͷඞཁ͋Γ

Slide 22

Slide 22 text

·ͱΊ w ͜Ε͸ߦ͚Δ͔΋͠Εͳ͍ʂ w όάΛݟ͚ͭͨΒԶ͕௚͢ɺͷؾ࣋ͪʢ࠶