sequelのすすめ - rabbit slide show · 2020. 7. 22. · sequelのすすめ -...

60
Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 Sequelのすすめ 〜私がSQLを嫌いな理由〜 とみたまさひろ RubyHiroba 2013 2013-06-02

Upload: others

Post on 23-Aug-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

Sequelのすすめ〜私がSQLを嫌いな理由〜

とみたまさひろRubyHiroba 2013

2013-06-02

Page 2: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

自己紹介とみた まさひろ

長野県北部在住

プログラマー (Ruby & C)

http://tmtms.hatenablog.com

http://twitter.com/tmtms

好きなもの

Ruby, MySQL, Linux Mint, Emacs, Git

Page 3: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

OSS貢献者賞

Page 4: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

諸君、私はSQLが嫌いだ

Page 5: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

select name from users where loginid = 'tmtms'

Page 6: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

英語っぽい

Page 7: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

どれが予約語やねん

Page 8: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

select name from users where loginid = 'tmtms'

Page 9: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

予約語が多い

Page 10: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

カラム名にgroupが使えなくて死ぬ

まぁクォートすればいいんだけども…

Page 11: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

余計な単語

Page 12: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

insert into tblname〜

select〜group by col

Page 13: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

insert into tblname〜

select〜group by col

Page 14: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

構文解析上なくてもいい

Page 15: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

英語っぽくするため(?)

RSpecのようなキモさ

Page 16: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

insertとupdateの構文の非対称

Page 17: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

insert into tbl (col1,col2) values (val1,val2)

update tbl set col1=val1,col2=val2

Page 18: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

全然違う

Page 19: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

MySQLはこれも可能

insert tbl set col1=val1,col2=val2

さすが変態

Page 20: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

集約関数

Page 21: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

select length(id) from tbl

select count(id) from tbl

Page 22: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

select length(id) from tbl→結果件数はレコード数

select count(id) from tbl→結果件数は1

Page 23: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

同じ構文なのに関数によって結果が異なる

Page 24: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

そんなこんなでSQL嫌い

Page 25: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

SQLを書かずにRDBを使うには

Page 26: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

Rubyで書けばいいじゃない

Page 27: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

そこでSequel

Page 28: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

テーブルの操作SELECT col2 FROM tbl WHERE col1=1

Page 29: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

条件で行の絞り込みSELECT col2 FROM tbl WHERE col1=1

Page 30: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

その中の列を選択SELECT col2 FROM tbl WHERE col1=1

Page 31: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

Sequelで

Page 32: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

Sequel 初期化

require 'sequel'DB = Sequel.connect( 'mysql://user:passwd@hostname:3306/dbname')

Page 33: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

コマンドラインから

% sequel mysql://user:passwd@hostname:3306/dbnameYour database is stored in DB...irb(main):001:0>

Page 34: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

テーブルの操作DB[:tbl]

Page 35: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

条件で行の絞り込みDB[:tbl].where(col1: 1)

Page 36: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

その中の列を選択DB[:tbl].where(col1: 1).select(:col2)

Page 37: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

とても自然!

Page 38: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

Select/Update/Delete/Insert

DB[:tbl].where(col1: 1).select(:col2)

DB[:tbl].where(col1: 1).update(col2: 3)

DB[:tbl].where(col1: 1).delete

DB[:tbl].insert(col1: 1, col2: 2)

Page 39: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

Select は実行遅延

ds = DB[:tbl].where(col1: 1).select(:col2) # まだ実行されないds.first # ここで実行される #=> {:col2=>'value'}

Page 40: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

関数

DB[:tbl].select(Sequel.function(:length, :col))#=> SELECT length(col) FROM tbl

DB[:tbl].select{length(col)}#=> SELECT length(col) FROM tbl

Page 41: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

集約関数

DB[:tbl].count#=> SELECT COUNT(*) FROM tbl

Page 42: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

条件いろいろ

Page 43: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

比較

where(id: 123)#=> WHERE id=123

Page 44: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

配列

where(id: [123, 456])#=> WHERE id IN (123, 456)

Page 45: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

Range

where(id: 123..456)#=> WHERE id >= 123 AND id <= 456

Page 46: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

nil, true, false

where(id: nil)#=> WHERE id is NULL

Page 47: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

データセット

where(id: DB[:tbl2].select(:id))#=> WHERE id IN (SELECT id FROM tbl2)

Page 48: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

正規表現

where(id: /abc/)#=> WHERE id REGEXP BINARY 'abc'

where(id: /abc/i)#=> WHERE id REGEXP 'abc'

Page 49: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

複数

where(id: 123, name:'hoge')#=> WHERE id=123 AND name='hoge'

Page 50: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

不等号

where(Sequel.expr(:id) > 123)#=> WHERE id > 123

where{id > 123}#=> WHERE id > 123

Page 51: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

JOIN

Page 52: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

JOIN

DB[:posts].left_join(:users, :id=>:users_id)#=> SELECT * FROM posts LEFT JOIN users# ON users.id=posts.users_id

Page 53: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

自己結合

DB[:hoge].left_join(:hoge.as(:fuga), :x=>:y). select(:hoge__id)#=> SELECT hoge.id FROM hoge# LEFT JOIN hoge AS fuga# ON fuga.x=hoge.y

Page 54: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

FAQ

Page 55: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

Q. ActiveRecord じゃだめなん?

Page 56: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

A1. Active Record は RDB にデータ置いて読み書きしてるだけで、

RDB として使ってるわけじゃないんでちょっと…

Page 57: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

A2. ActiveRecord はRuby/MySQL で動かないし…

そういえば activerecord-ruby_mysql-adapter ってのを作ったような気もする

Page 58: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

A3. でも Active Record 便利ですよね。Sequel でも使えるよ!

Page 59: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

Sequel::Model

class User < Sequel::Model plugin :validation_helpers

def validate super validates_unique :loginid validates_presence :name endend

Page 60: Sequelのすすめ - Rabbit Slide Show · 2020. 7. 22. · Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7 まとめ SQL の構文はイケてない(個人の感想です)

Sequelのすすめ - 〜私がSQLを嫌いな理由〜 Powered by Rabbit 2.0.7

まとめ

SQL の構文はイケてない(個人の感想です)

Sequel で Ruby っぽくクエリを書ける

Sequel は Active Record パターンも使える

SQL を「シークエル」と発音する人は混乱するがいいさ