webappdev勉強会 #3 at cafe? ikagawa do

22
Web Application Devlopment Webアプリ開発 #3 05.23.12

Upload: kohei-noda

Post on 22-Jul-2015

264 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: WebAppDev勉強会 #3 at cafe? IKAGAWA DO

Web Application Devlopment

Webアプリ開発#3

05.23.12

Page 2: WebAppDev勉強会 #3 at cafe? IKAGAWA DO

Presented by U-moa

Page 3: WebAppDev勉強会 #3 at cafe? IKAGAWA DO

Agenda

1. 自己紹介タイム

2. ワークショップSinatraではじめるWebアプリ開発 #2

3. LT(あれば)

4. ふりかえり

Page 4: WebAppDev勉強会 #3 at cafe? IKAGAWA DO

Self-Introduction

自己紹介タイム

Page 5: WebAppDev勉強会 #3 at cafe? IKAGAWA DO

Self-Introduction

• 名前

• 所属

• 好きなこと、最近やっていることなどなど・・・

Page 6: WebAppDev勉強会 #3 at cafe? IKAGAWA DO

Workshop

ワークショップ

Page 7: WebAppDev勉強会 #3 at cafe? IKAGAWA DO

WorkShop

今日の目標

簡単なブログを作ってみよう

Page 8: WebAppDev勉強会 #3 at cafe? IKAGAWA DO

Sinatraではじめる

Webアプリ開発 #3Sinatra is a DSL for quickly creating

web application in Ruby with minimal

effort:

Page 9: WebAppDev勉強会 #3 at cafe? IKAGAWA DO

ウォームアップを兼ねて前回のおさらい

Page 10: WebAppDev勉強会 #3 at cafe? IKAGAWA DO

Sequelの復習

Page 11: WebAppDev勉強会 #3 at cafe? IKAGAWA DO

テーブルを作ろう

• sequelをrequireしよう

• データベースへ接続するコードを書こう

• テーブルを定義しよう(テーブル名と項目は自由に)

Page 12: WebAppDev勉強会 #3 at cafe? IKAGAWA DO

テーブルを作ろう1 # coding: utf-8

2 require 'rubygems'

3 require 'sequel'

4

5 Sequel::Model.plugin(:schema)

6 DB = Sequel.sqlite('database.sqlite3') ## SQLite3

7

8 class Person < Sequel::Model

9 unless table_exists?

10 set_schema do

11 primary_key :id

12 string :name

13 integer :age

14 end

15

16 create_table

17 end

18 end

DBへの接続

テーブルの名前

項目の定義

Page 13: WebAppDev勉強会 #3 at cafe? IKAGAWA DO

データを追加してみよう

• テーブルにデータを追加してみよう

• 2つ以上データを追加すること

Page 14: WebAppDev勉強会 #3 at cafe? IKAGAWA DO

データを追加してみよう

1 # coding: utf-8

2 require 'rubygems'

3 require 'sequel'

4

…… 中略19

20 Person.create(:name => 'Pamyu Pamyu', :age => 19)

21 Person.create(:name => ’Yasutaka', :age => 32)

22

Page 15: WebAppDev勉強会 #3 at cafe? IKAGAWA DO

データを取り出してみよう

• 先程追加したデータを検索して取り出してみよう

1. 最初に見つかった一件だけ取り出そう

2. 見つかったもの全てを取り出そう

3. 全てのデータを取り出そう

Page 16: WebAppDev勉強会 #3 at cafe? IKAGAWA DO

データを取り出してみよう

1 # coding: utf-8

2 require 'rubygems'

3 require 'sequel'

4

…… 中略21

22 # 一行取得23 Person.first(:name => 'Sato')

24

25 # 一部の行を取得26 Person.filter(:age => 19).all

27

28 # 全部の行を取得29 Person.all

Page 17: WebAppDev勉強会 #3 at cafe? IKAGAWA DO

前回はこんな内容でした

Page 18: WebAppDev勉強会 #3 at cafe? IKAGAWA DO

それでは

Page 19: WebAppDev勉強会 #3 at cafe? IKAGAWA DO

Blogを作ってみよう

Page 20: WebAppDev勉強会 #3 at cafe? IKAGAWA DO

Retrospectives

ふりかえり

Page 21: WebAppDev勉強会 #3 at cafe? IKAGAWA DO

Keep

Problem

Try

Page 22: WebAppDev勉強会 #3 at cafe? IKAGAWA DO

Keep = 良かったところ

Problem = 悪かったところ

Try = 次回の取り組み