rabbit-slide-tommy-sequel 2013.06.02

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 15cf289c677f2bafaffe88694788eafde5897a75
4
+ data.tar.gz: 277b2bbf1c3028350a9134c4dce81f924c5f9fdf
5
+ SHA512:
6
+ metadata.gz: f6165a4837c32bf16e0d00551e625d7e5d2a813e697b1ad598a6911a415d6aaeac14b5f86c4db98172b4d6b77dd6ccaad8154b5063e5970e57f485c0db2bb7c0
7
+ data.tar.gz: 661ae3a60a2db5dd6b0e2702df045faf63c66d9f9096c89e8a60278ae37686e210f21955bc6c79fc381ce557fe29ee9c47faf1d3ddc84a8f608d5db67a670104
data/.rabbit ADDED
@@ -0,0 +1 @@
1
+ sequel.rab
@@ -0,0 +1,24 @@
1
+ = Sequelのすすめ
2
+
3
+ Sequel を使って Ruby でクエリを書こう
4
+
5
+ == 作者向け
6
+
7
+ === 表示
8
+
9
+ rake
10
+
11
+ === 公開
12
+
13
+ rake publish
14
+
15
+ == 閲覧者向け
16
+
17
+ === インストール
18
+
19
+ gem install rabbit-slide-tommy-sequel
20
+
21
+ === 表示
22
+
23
+ rabbit rabbit-slide-tommy-sequel.gem
24
+
@@ -0,0 +1,9 @@
1
+ require "rabbit/task/slide"
2
+
3
+ # Edit ./config.yaml to customize meta data
4
+
5
+ Rabbit::Task::Slide.new do |task|
6
+ # task.spec.files += Dir.glob("doc/**/*.*")
7
+ # task.spec.files -= Dir.glob("private/**/*.*")
8
+ # task.spec.add_runtime_dependency("YOUR THEME")
9
+ end
@@ -0,0 +1,18 @@
1
+ ---
2
+ id: sequel
3
+ base_name: sequel
4
+ tags: []
5
+ presentation_date: 2013/06/02
6
+ version: 2013.06.02
7
+ licenses: []
8
+ slideshare_id:
9
+ speaker_deck_id:
10
+ ustream_id:
11
+ vimeo_id:
12
+ author:
13
+ markup_language: :rd
14
+ name: とみたまさひろ
15
+ email: tommy@tmtm.org
16
+ rubygems_user: tommy
17
+ slideshare_user:
18
+ speaker_deck_user:
Binary file
@@ -0,0 +1,290 @@
1
+ = Sequelのすすめ
2
+
3
+ : subtitle
4
+ 〜私がSQLを嫌いな理由〜
5
+ : author
6
+ とみたまさひろ
7
+ # : institution
8
+ # 所属
9
+ : content-source
10
+ RubyHiroba 2013
11
+ : date
12
+ 2013-06-02
13
+ : allotted-time
14
+ 5m
15
+ : theme
16
+ clear-blue+
17
+
18
+ = 自己紹介
19
+
20
+ * とみた まさひろ
21
+ * 長野県北部在住
22
+ * プログラマー (((*Ruby*)) & C)
23
+ * http://((*tmtms*)).hatenablog.com
24
+ * http://twitter.com/((*tmtms*))
25
+ * 好きなもの
26
+ * ((*Ruby*)), MySQL, Linux Mint, Emacs, Git
27
+
28
+ = OSS貢献者賞
29
+
30
+ # image
31
+ # src = OSS貢献者賞.jpg
32
+ # relative_height = 100
33
+
34
+ = 諸君、私はSQLが嫌いだ
35
+
36
+ = select name from users\n where loginid = 'tmtms'
37
+
38
+ = 英語っぽい
39
+
40
+ = どれが予約語やねん
41
+
42
+ = ((*select*)) name ((*from*)) users\n ((*where*)) loginid = 'tmtms'
43
+
44
+ = 予約語が多い
45
+
46
+ = カラム名に((*group*))が\n使えなくて死ぬ\n\n(('note:まぁクォートすればいいんだけども…'))
47
+
48
+ = 余計な単語
49
+
50
+ = insert into tblname〜\n\nselect〜group by col
51
+
52
+ = insert ((*into*)) tblname〜\n\nselect〜group ((*by*)) col
53
+
54
+ = 構文解析上なくてもいい
55
+
56
+ = 英語っぽくするため(?)\n\n(('note:RSpecのようなキモさ'))
57
+
58
+ = insertとupdateの\n構文の非対称
59
+
60
+ = insert into tbl (col1,col2) values (val1,val2)\n\nupdate tbl set col1=val1,col2=val2
61
+
62
+ = 全然違う
63
+
64
+ = MySQLはこれも可能\n\ninsert tbl set col1=val1,col2=val2\n\n(('note:さすが変態'))
65
+
66
+ = 集約関数
67
+
68
+ = select ((*length*))(id) from tbl\n\nselect ((*count*))(id) from tbl
69
+
70
+ = select ((*length*))(id) from tbl\n→結果件数は((*レコード数*))\n\nselect ((*count*))(id) from tbl\n→結果件数は((*1*))
71
+
72
+ = 同じ構文なのに\n関数によって結果が異なる
73
+
74
+ = そんなこんなでSQL嫌い
75
+
76
+ = SQLを書かずにRDBを使うには
77
+
78
+ = ((*Ruby*))で書けばいいじゃない
79
+
80
+ = そこでSequel
81
+
82
+ = テーブルの操作
83
+
84
+ SELECT col2 ((*FROM tbl*)) WHERE col1=1
85
+
86
+ # image
87
+ # src = table1.png
88
+ # relative_height = 100
89
+
90
+ = 条件で行の絞り込み
91
+
92
+ SELECT col2 FROM tbl ((*WHERE col1=1*))
93
+
94
+ # image
95
+ # src = table2.png
96
+ # relative_height = 100
97
+
98
+ = その中の列を選択
99
+
100
+ ((*SELECT col2*)) FROM tbl WHERE col1=1
101
+
102
+ # image
103
+ # src = table3.png
104
+ # relative_height = 100
105
+
106
+ = Sequelで
107
+
108
+ = Sequel 初期化
109
+
110
+ # enscript ruby
111
+ require 'sequel'
112
+ DB = Sequel.connect(
113
+ 'mysql://user:passwd@hostname:3306/dbname'
114
+ )
115
+
116
+ = コマンドラインから
117
+
118
+ % sequel mysql://user:passwd@hostname:3306/dbname
119
+ Your database is stored in DB...
120
+ irb(main):001:0>
121
+
122
+ = テーブルの操作
123
+
124
+ ((*DB[:tbl]*))
125
+
126
+ # image
127
+ # src = table1.png
128
+ # relative_height = 100
129
+
130
+ = 条件で行の絞り込み
131
+
132
+ DB[:tbl].((*where(col1: 1)*))
133
+
134
+ # image
135
+ # src = table2.png
136
+ # relative_height = 100
137
+
138
+ = その中の列を選択
139
+
140
+ DB[:tbl].where(col1: 1).((*select(:col2)*))
141
+
142
+ # image
143
+ # src = table3.png
144
+ # relative_height = 100
145
+
146
+ = とても自然!
147
+
148
+ = Select/Update/Delete/Insert
149
+
150
+ # enscript ruby
151
+ DB[:tbl].where(col1: 1).select(:col2)
152
+
153
+ DB[:tbl].where(col1: 1).update(col2: 3)
154
+
155
+ DB[:tbl].where(col1: 1).delete
156
+
157
+ DB[:tbl].insert(col1: 1, col2: 2)
158
+
159
+ = Select は実行遅延
160
+
161
+ # enscript ruby
162
+
163
+ ds = DB[:tbl].where(col1: 1).select(:col2)
164
+ # まだ実行されない
165
+ ds.first
166
+ # ここで実行される
167
+ #=> {:col2=>'value'}
168
+
169
+ = 関数
170
+
171
+ # enscript ruby
172
+
173
+ DB[:tbl].select(Sequel.function(:length, :col))
174
+ #=> SELECT length(col) FROM tbl
175
+
176
+ DB[:tbl].select{length(col)}
177
+ #=> SELECT length(col) FROM tbl
178
+
179
+ = 集約関数
180
+
181
+ # enscript ruby
182
+
183
+ DB[:tbl].count
184
+ #=> SELECT COUNT(*) FROM tbl
185
+
186
+ = 条件いろいろ
187
+
188
+ = 比較
189
+
190
+ # enscript ruby
191
+ where(id: 123)
192
+ #=> WHERE id=123
193
+
194
+ = 配列
195
+
196
+ # enscript ruby
197
+ where(id: [123, 456])
198
+ #=> WHERE id IN (123, 456)
199
+
200
+ = Range
201
+
202
+ # enscript ruby
203
+ where(id: 123..456)
204
+ #=> WHERE id >= 123 AND id <= 456
205
+
206
+ = nil, true, false
207
+
208
+ # enscript ruby
209
+ where(id: nil)
210
+ #=> WHERE id is NULL
211
+
212
+ = データセット
213
+
214
+ # enscript ruby
215
+ where(id: DB[:tbl2].select(:id))
216
+ #=> WHERE id IN (SELECT id FROM tbl2)
217
+
218
+ = 正規表現
219
+
220
+ # enscript ruby
221
+ where(id: /abc/)
222
+ #=> WHERE id REGEXP BINARY 'abc'
223
+
224
+ where(id: /abc/i)
225
+ #=> WHERE id REGEXP 'abc'
226
+
227
+ = 複数
228
+
229
+ # enscript ruby
230
+ where(id: 123, name:'hoge')
231
+ #=> WHERE id=123 AND name='hoge'
232
+
233
+ = 不等号
234
+
235
+ # enscript ruby
236
+ where(Sequel.expr(:id) > 123)
237
+ #=> WHERE id > 123
238
+
239
+ where{id > 123}
240
+ #=> WHERE id > 123
241
+
242
+ = JOIN
243
+
244
+ = JOIN
245
+
246
+ # enscript ruby
247
+
248
+ DB[:posts].left_join(:users, :id=>:users_id)
249
+ #=> SELECT * FROM posts LEFT JOIN users
250
+ # ON users.id=posts.users_id
251
+
252
+ = 自己結合
253
+
254
+ # enscript ruby
255
+
256
+ DB[:hoge].left_join(:hoge.as(:fuga), :x=>:y).
257
+ select(:hoge__id)
258
+ #=> SELECT hoge.id FROM hoge
259
+ # LEFT JOIN hoge AS fuga
260
+ # ON fuga.x=hoge.y
261
+
262
+ = FAQ
263
+
264
+ = Q. ActiveRecord じゃだめなん?
265
+
266
+ = A1. Active Record は RDB にデータ置いて読み書きしてるだけで、RDB として使ってるわけじゃないんでちょっと…
267
+
268
+ = A2. ActiveRecord は\nRuby/MySQL で動かないし…\n\n(('note:そういえば activerecord-ruby_mysql-adapter ってのを作ったような気もする'))
269
+
270
+ = A3. でも Active Record 便利ですよね。Sequel でも使えるよ!
271
+
272
+ = Sequel::Model
273
+
274
+ # enscript ruby
275
+ class User < Sequel::Model
276
+ plugin :validation_helpers
277
+
278
+ def validate
279
+ super
280
+ validates_unique :loginid
281
+ validates_presence :name
282
+ end
283
+ end
284
+
285
+ = まとめ
286
+
287
+ * SQL の構文はイケてない(('note:(個人の感想です)'))
288
+ * Sequel で Ruby っぽくクエリを書ける
289
+ * Sequel は Active Record パターンも使える
290
+ * SQL を「シークエル」と発音する人は混乱するがいいさ
Binary file
Binary file
Binary file
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rabbit-slide-tommy-sequel
3
+ version: !ruby/object:Gem::Version
4
+ version: 2013.06.02
5
+ platform: ruby
6
+ authors:
7
+ - とみたまさひろ
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-06-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rabbit
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 2.0.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 2.0.2
27
+ description: Sequel を使って Ruby でクエリを書こう
28
+ email:
29
+ - tommy@tmtm.org
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - .rabbit
35
+ - config.yaml
36
+ - Rakefile
37
+ - README.rd
38
+ - table2.png
39
+ - table1.png
40
+ - table3.png
41
+ - OSS貢献者賞.jpg
42
+ - sequel.rab
43
+ - pdf/sequel-sequel.pdf
44
+ homepage: http://slide.rabbit-shocker.org/authors/tommy/sequel/
45
+ licenses: []
46
+ metadata: {}
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubyforge_project:
63
+ rubygems_version: 2.0.0
64
+ signing_key:
65
+ specification_version: 4
66
+ summary: Sequelのすすめ
67
+ test_files: []