update pod
|
1 |
=encoding utf8 |
2 | ||
added DBIx::Custom::Guides
|
3 |
=head1 NAME |
4 | ||
update pod
|
5 |
DBIx::Custom::Guide - DBIx::Custom Guide |
added DBIx::Custom::Guides
|
6 | |
pod fix
|
7 |
=head1 GUIDE |
added DBIx::Custom::Guides
|
8 | |
update pod
|
9 |
B<This guide is now writing.> |
update pod
|
10 | |
update pod
|
11 |
L<DBIx::Custom> is the class to make easy to execute SQL. |
12 |
This is L<DBI> wrapper class like L<DBIx::Class> or L<DBIx::Simple>. |
|
13 |
You can do thing more easy than L<DBIx::Class>, more flexible |
|
14 |
than L<DBIx::Simple>. |
|
added DBIx::Custom::Guides
|
15 | |
update pod
|
16 |
L<DBIx::Custom> is B<not< O/R mapper, O/R mapper is usefule, but |
17 |
you must learn many things. Created SQL is sometimes inefficient, |
|
18 |
and in many cases you create raw SQL because |
|
19 |
O/R mapper can't make complex SQL |
|
added DBIx::Custom::Guides
|
20 | |
update pod
|
21 |
L<DBIx::Custom> is opposit of O/R mapper. |
22 |
The main purpose is that we respect SQL |
|
23 |
and make easy difficult works if you use only L<DBI>. |
|
24 |
If you already learn SQL, it is easy to use L<DBIx::Custom>. |
|
deprecated DBIx::Custom::MyS...
|
25 | |
update pod
|
26 |
I explain L<DBIx::Custom> a little in this section. |
27 |
In L<DBIx::Custom>, you embbed tag in SQL. |
|
deprecated DBIx::Custom::MyS...
|
28 | |
update pod
|
29 |
select * from book where {= title} and {=author}; |
deprecated DBIx::Custom::MyS...
|
30 | |
update pod
|
31 |
The part arround {} is tag. |
32 |
This SQL is converted to the one which contains place holder. |
|
33 | ||
34 |
select * from book where title = ? and author = ?; |
|
35 | ||
36 |
Maybe you ask me that this conversion is meaningful. |
|
37 |
On the top of this, usuful features is implemented. |
|
38 |
See the following descriptions. |
|
39 | ||
40 |
=over 4 |
|
41 | ||
42 |
=item 1. Specify place holder binding value as hash refernce |
|
43 | ||
44 |
If you use L<DBI>, you must specify place holder binding value |
|
45 |
as array. |
|
46 | ||
47 |
$sth->execute(@bind); |
|
48 | ||
49 |
If you use L<DBIx::Custom>, you specify it as hash reference. |
|
50 |
|
|
51 |
my $param = {title => 'Perl', author => 'Ken'}; |
|
52 |
$dbi->execute($sql, $param); |
|
53 | ||
54 |
=item 2. Filtering |
|
55 | ||
56 |
L<DBIx::Custom> provides filtering system. |
|
57 |
For example, You think that about date value you want to |
|
58 |
manipulate it as date object like L<Time::Piece> in Perl, |
|
59 |
and want to convert it to database DATE format. |
|
60 |
and want to do reverse. |
|
61 | ||
62 |
You can use filtering system. |
|
63 | ||
64 |
At first, register filter. |
|
65 | ||
66 |
$dbi->register_filter( |
|
67 |
tp_to_date => sub { |
|
68 |
... |
|
69 |
}, |
|
70 |
date_to_tp => sub { |
|
71 |
... |
|
72 |
} |
|
73 |
); |
|
74 | ||
75 |
next, apply this filter to each column. |
|
76 | ||
77 |
$dbi->apply_filter('book', |
|
78 |
'issue_date' => {out => 'tp_to_date', in => 'date_to_tp'} |
|
79 |
); |
|
80 | ||
81 |
C<out> is perl-to-database way. C<in> is perl-from-database way. |
|
82 | ||
83 |
This filter is automatically enabled in many method. |
|
84 | ||
85 |
$dbi->insert(table => 'book', param => {issue_date => $tp}); |
|
86 | ||
87 | ||
88 |
=item 3. Selective search condition |
|
89 | ||
90 |
It is difficult to create selective where clause in L<DBI>. |
|
91 |
For example, If C<title> and C<author> is specified, we create |
|
92 |
the following SQL. |
|
93 | ||
94 |
select * from book where title = ? and author = ?; |
|
95 | ||
96 |
If only C<title> is specified, the following one |
|
97 | ||
98 |
select * from book where title = ?; |
|
99 | ||
100 |
If only C<author> is specified, the following one, |
|
101 | ||
102 |
select * from book where author = ?; |
|
103 | ||
104 |
This is hard work. Generally we use modules like L<SQL::Abstract>. |
|
105 |
L<DBIx::Custom> prepare the way to make it easy. |
|
106 | ||
107 |
# Where object |
|
108 |
my $where = $dbi->where; |
|
109 |
|
|
110 |
# Search condition |
|
111 |
$where->clause( |
|
112 |
['and', '{= title}', {'= author'}] |
|
113 |
); |
|
114 |
|
|
115 |
# Setting to automatically select needed column |
|
116 |
$where->param({title => 'Perl'}); |
|
117 | ||
118 |
# Embbed where clause to SQL |
|
119 |
my $sql = "select * from book $where"; |
|
120 | ||
121 |
You can create where clause which has selected search condition. |
|
122 |
You can write nesting of where clause and C<or> condition |
|
123 | ||
update pod
|
124 |
=item 4. Methods for insert, update, delete, select |
update pod
|
125 | |
update pod
|
126 |
L<DBIx::Custom> provides methods for insert, update, delete, select |
127 |
There are C<insert()>, C<update()>, C<delete()>,C<select()>. |
|
update pod
|
128 | |
129 |
my $param = {title => 'Perl', author => 'Ken'}; |
|
130 |
$dbi->insert(table => 'book', param => $param); |
|
131 | ||
update pod
|
132 |
=item 5. Register method for table. |
deprecated DBIx::Custom::MyS...
|
133 | |
update pod
|
134 |
You can register method for table. |
update pod
|
135 | |
update pod
|
136 |
$dbi->table('book')->method( |
update pod
|
137 |
list => sub { |
138 |
... |
|
139 |
}, |
|
update pod
|
140 |
something => sub { |
141 |
... |
|
update pod
|
142 |
} |
143 |
); |
|
144 | ||
update pod
|
145 |
use the mehtod. |
update pod
|
146 | |
147 |
$dbi->table('book')->list; |
|
148 | ||
update pod
|
149 |
Many O/R mapper must create class for table, |
150 |
but L<DBIx::Custom> make it easy. |
|
update pod
|
151 | |
152 |
=back |
|
153 | ||
update pod
|
154 |
L<DBIx::Custom> is very useful. |
155 |
See the following if you are interested in it. |
|
update pod
|
156 | |
update pod
|
157 |
=head2 1. Connect to database |
update pod
|
158 | |
update pod
|
159 |
Load L<DBIx::Custom>. |
update pod
|
160 | |
161 |
use DBIx::Custom; |
|
162 | ||
update pod
|
163 |
use C<connect()> to connect to database. |
164 |
Return value is L<DBIx::Custom> object. |
|
update pod
|
165 | |
166 |
my $dbi = DBIx::Custom->connect( |
|
update pod
|
167 |
data_source => "dbi:mysql:database=bookstore", |
update pod
|
168 |
user => 'ken', |
169 |
password => '!LFKD%$&', |
|
170 |
dbi_options => {mysql_enable_utf8 => 1} |
|
171 |
); |
|
172 | ||
update pod
|
173 |
C<data_source> must be one corresponding to the database system. |
174 |
The following ones are data source example. |
|
update pod
|
175 | |
176 |
B<MySQL> |
|
remove DBIx::Custom::Model
|
177 | |
178 |
"dbi:mysql:database=$database" |
|
179 |
"dbi:mysql:database=$database;host=$hostname;port=$port" |
|
180 | ||
update pod
|
181 |
B<SQLite> |
182 | ||
183 |
"dbi:SQLite:dbname=$database" |
|
184 |
"dbi:SQLite:dbname=:memory:" |
|
185 | ||
186 |
B<PostgreSQL> |
|
deprecated DBIx::Custom::MyS...
|
187 | |
188 |
"dbi:Pg:dbname=$dbname" |
|
189 | ||
update pod
|
190 |
B<Oracle> |
deprecated DBIx::Custom::MyS...
|
191 | |
192 |
"dbi:Oracle:$dbname" |
|
193 |
"dbi:Oracle:host=$host;sid=$sid" |
|
194 | ||
update pod
|
195 |
B<ODBC(Microsoft Access)> |
deprecated DBIx::Custom::MyS...
|
196 | |
197 |
"dbi:ODBC:driver=Microsoft Access Driver (*.mdb);dbq=hoge.mdb" |
|
198 | ||
update pod
|
199 |
B<ODBC(SQL Server)> |
deprecated DBIx::Custom::MyS...
|
200 | |
201 |
"dbi:ODBC:driver={SQL Server};Server=(local);database=test;Trusted_Connection=yes;AutoTranslate=No;" |
|
added DBIx::Custom::Guides
|
202 | |
update pod
|
203 |
If authentication is needed, you can specify C<user> and C<password> |
204 | ||
205 |
L<DBIx::Custom> is wrapper class of L<DBI>. |
|
206 |
You can use all methods of L<DBI> from L<DBIx::Custom> object. |
|
207 | ||
208 |
$dbi->do(...); |
|
209 |
$dbi->begin_work; |
|
update pod
|
210 | |
update pod
|
211 |
use C<dhb()> to get database handle of L<DBI> |
added DBIx::Custom::Guides
|
212 | |
update pod
|
213 |
my $dbh = $dbi->dbh; |
added DBIx::Custom::Guides
|
214 | |
update pod
|
215 |
By default, the following ones is set to database handle attributes. |
216 | ||
217 |
RaiseError -> 1 |
|
218 |
PrintError -> 0 |
|
219 |
AutoCommit -> 1 |
|
added DBIx::Custom::Guides
|
220 | |
update pod
|
221 |
If fatal error occuer, program terminate. |
222 |
If SQL is executed, commit is executed automatically. |
|
update pod
|
223 | |
224 |
=head2 2. �}��A�X�V�A�폜�A�I��̂��߂̃��\�b�h |
|
225 | ||
226 |
L<DBIx::Custom>�́A |
|
227 |
C<insert()>�AC<update()>�AC<delete()>�AC<select()> |
|
228 |
�̂悤�ȑ}��A�X�V�A�폜�A�I���s�����߂̃��\�b�h���Ă��܂��B |
|
229 |
�ȒP�Ȃ��Ƃ��s���̂ł���ASQL����ŋL�q����K�v������܂���B |
|
230 | ||
231 |
=head3 �f�[�^�̑}�� C<insert()> |
|
232 | ||
233 |
�f�[�^�x�[�X�Ƀf�[�^��}���ɂ�C<insert()>��g�p���܂��B |
|
added DBIx::Custom::Guides
|
234 | |
remove DBIx::Custom::Model
|
235 |
$dbi->insert(table => 'book', |
added DBIx::Custom::Guides
|
236 |
param => {title => 'Perl', author => 'Ken'}); |
237 | ||
update pod
|
238 |
C<table>�ɂ̓e�[�u�����AC<param>�ɂ͑}����f�[�^��w�肵�܂��B |
added DBIx::Custom::Guides
|
239 | |
update pod
|
240 |
����SQL�����s����܂��B |
added DBIx::Custom::Guides
|
241 | |
update pod
|
242 |
insert into (title, author) values (?, ?); |
added DBIx::Custom::Guides
|
243 | |
update pod
|
244 |
=head3 �f�[�^�̍X�V C<update()> |
added DBIx::Custom::Guides
|
245 | |
update pod
|
246 |
�f�[�^�x�[�X�̃f�[�^��X�V����ɂ́AC<update()>��g�p���܂��B |
added DBIx::Custom::Guides
|
247 | |
remove DBIx::Custom::Model
|
248 |
$dbi->update(table => 'book', |
added DBIx::Custom::Guides
|
249 |
param => {title => 'Perl', author => 'Ken'}, |
250 |
where => {id => 5}); |
|
251 | ||
update pod
|
252 |
C<table>�ɂ̓e�[�u�����AC<param>�ɂ͑}����f�[�^�AC<where>�ɂ� |
253 |
���w�肵�܂��B |
|
added DBIx::Custom::Guides
|
254 | |
update pod
|
255 |
����SQL�����s����܂��B |
added DBIx::Custom::Guides
|
256 | |
update pod
|
257 |
update book set title = ?, author = ?; |
added DBIx::Custom::Guides
|
258 | |
update pod
|
259 |
C<update>���\�b�h�͈�S�̂��� |
260 |
where��̂Ȃ�SQL�s���邱�Ƃ���Ă��܂���B |
|
261 |
�����ׂĂ̍s��X�V�������ꍇ�� |
|
262 |
C<update_all()>��g�p�����������B |
|
added DBIx::Custom::Guides
|
263 | |
update pod
|
264 |
$dbi->update_all(table => 'book', |
265 |
param => {title => 'Perl', author => 'Ken'}); |
|
added DBIx::Custom::Guides
|
266 | |
update pod
|
267 |
=head3 �f�[�^�̍폜 C<delete()> |
added DBIx::Custom::Guides
|
268 | |
update pod
|
269 |
�f�[�^�x�[�X�̃f�[�^��1���폜����ɂ́AC<delete()>��g�p���܂��B |
added DBIx::Custom::Guides
|
270 | |
remove DBIx::Custom::Model
|
271 |
$dbi->delete(table => 'book', |
added DBIx::Custom::Guides
|
272 |
where => {author => 'Ken'}); |
273 | ||
update pod
|
274 |
C<table>�ɂ̓e�[�u�����AC<where>�ɂ͏��w�肵�܂��B |
added DBIx::Custom::Guides
|
275 | |
update pod
|
276 |
����SQL�����s����܂��B |
added DBIx::Custom::Guides
|
277 | |
update pod
|
278 |
delete from book where id = ?; |
added DBIx::Custom::Guides
|
279 | |
update pod
|
280 |
C<delete>���\�b�h�͈�S�̂��� |
281 |
where��̂Ȃ�SQL�s���邱�Ƃ���Ă��܂���B |
|
282 |
�����ׂĂ̍s��폜�������ꍇ�� |
|
283 |
C<delete_all()>��g�p�����������B |
|
added DBIx::Custom::Guides
|
284 | |
update pod
|
285 |
$dbi->delete_all(table => 'book'); |
added DBIx::Custom::Guides
|
286 | |
update pod
|
287 |
=head3 �f�[�^�̑I�� C<select()> |
added DBIx::Custom::Guides
|
288 | |
update pod
|
289 |
�s��I���ɂ�C<select()>��g�p���܂��B |
added DBIx::Custom::Guides
|
290 | |
remove DBIx::Custom::Model
|
291 |
my $result = $dbi->select(table => 'book'); |
added DBIx::Custom::Guides
|
292 | |
update pod
|
293 |
C<table>������w�肵�āA���̏��w�肵�Ȃ��ꍇ�͎���SQL�����s����܂��B |
added DBIx::Custom::Guides
|
294 | |
remove DBIx::Custom::Model
|
295 |
select * from book; |
added DBIx::Custom::Guides
|
296 | |
update pod
|
297 |
C<select()>���\�b�h�̖߂�l��L<DBIx::Custom::Result> |
298 |
�I�u�W�F�N�g�ł��B�s��t�F�b�`����ɂ�C<fetch()>��g�p���܂��B |
|
added DBIx::Custom::Guides
|
299 | |
300 |
while (my $row = $result->fetch) { |
|
301 |
my $title = $row->[0]; |
|
302 |
my $author = $row->[1]; |
|
303 |
} |
|
304 | ||
update pod
|
305 |
L<DBIx::Custom::Result>�ɂ��Ă͂��̌�L<3. �s�̃t�F�b�`/"3. �s�̃t�F�b�`">�ŏڂ��������܂��B |
added DBIx::Custom::Guides
|
306 | |
update pod
|
307 |
���܂��܂�C<select()>�̎g�����Ă����܂��傤�B |
308 |
����C<select>�͍s�̖��O��where���w�肵����̂ł��B |
|
added DBIx::Custom::Guides
|
309 | |
310 |
my $result = $dbi->select( |
|
remove DBIx::Custom::Model
|
311 |
table => 'book', |
update pod
|
312 |
column => ['author', 'title'], |
added DBIx::Custom::Guides
|
313 |
where => {author => 'Ken'} |
314 |
); |
|
315 | ||
update pod
|
316 |
C<column>�ɂ͗�AC<where>�ɂ͏��w�肷�邱�Ƃ��ł��܂��B |
317 |
����SQL�����s����܂��B |
|
added DBIx::Custom::Guides
|
318 | |
remove DBIx::Custom::Model
|
319 |
select author, title from book where author = ?; |
added DBIx::Custom::Guides
|
320 | |
update pod
|
321 |
�e�[�u������������ꍇ�͂�C<relation>�Ƀe�[�u���� |
322 |
�W��L�q���܂��B |
|
added DBIx::Custom::Guides
|
323 | |
324 |
my $result = $dbi->select( |
|
remove DBIx::Custom::Model
|
325 |
table => ['book', 'rental'], |
update pod
|
326 |
where => {book.name => 'Perl'}, |
remove DBIx::Custom::Model
|
327 |
relation => {'book.id' => 'rental.book_id'} |
added DBIx::Custom::Guides
|
328 |
); |
329 | ||
update pod
|
330 |
book�e�[�u����id���rental�e�[�u����book_id���֘A�t�����܂��B |
331 |
����SQL�����s����܂��B |
|
added DBIx::Custom::Guides
|
332 | |
update pod
|
333 |
select * from book, rental where book.name = ? and book.id = rental.book_id; |
added DBIx::Custom::Guides
|
334 | |
update pod
|
335 |
SQL���̖���ɕ������lj�������ꍇ��<append>��g�p���܂��B |
added DBIx::Custom::Guides
|
336 | |
337 |
my $result = $dbi->select( |
|
remove DBIx::Custom::Model
|
338 |
table => 'book', |
added DBIx::Custom::Guides
|
339 |
where => {author => 'Ken'}, |
update pod
|
340 |
append => 'for update', |
added DBIx::Custom::Guides
|
341 |
); |
342 | ||
update pod
|
343 |
����SQL�����s����܂��B |
added DBIx::Custom::Guides
|
344 | |
update pod
|
345 |
select * book where author = ? for update; |
added DBIx::Custom::Guides
|
346 | |
update pod
|
347 |
�܂�C<append>�́AC<select>�����łȂ�C<insert()>�AC<update()>�AC<update_all()> |
348 |
C<delete()>�AC<delete_all()>�AC<select()>�Ŏg�p���邱�Ƃ�ł��܂��B |
|
added DBIx::Custom::Guides
|
349 | |
update pod
|
350 |
=head3 SQL�̎�s C<execute()> |
added DBIx::Custom::Guides
|
351 | |
update pod
|
352 |
�C�ӂ�SQL���s����ɂ�execute���\�b�h��g�p���܂��B |
353 | ||
354 |
$dbi->execute("select * from book;"); |
|
355 | ||
356 |
C<execute()>��L<DBIx::Custom>�̍����̃��\�b�h�ł���^�O��W�J���܂��B |
|
357 | ||
358 |
$dbi->execute( |
|
359 |
"select * from book {= title} and {= author};" |
|
360 |
param => {title => 'Perl', author => 'Ken'} |
|
361 |
); |
|
362 | ||
363 |
��L�̃^�O��܂�SQL�͎��̂悤�ɓW�J����܂��B |
|
364 | ||
365 |
select * from book title = ? and author = ?; |
|
366 | ||
367 |
SQL����s�����Ƃ��Ƀv���[�X�z���_(?)�ɑΉ�����ʒu��title��author |
|
368 |
�̒l���������I�ɖ��ߍ��܂�܂��B |
|
369 | ||
370 |
�^�O�ɂ��Ă�L<5. �^�O/"5. �^�O">�ŏڂ�������܂����A |
|
371 |
�ЂƂ̒��ӓ_������܂��B |
|
372 |
�^�O��W�J���邽�߂�C<{>��C<}>�͗\���ɂȂ�Ă��܂��B |
|
373 |
�����p�������ꍇ�͒��O��\����ăG�X�P�[�v��s���K�v������܂��B |
|
374 | ||
375 |
$dbi->execute("... \\{ ... \\} ..."); |
|
376 | ||
377 |
\���̂�Perl�̃G�X�P�[�v�����ł��̂ŁA��K�v�ɂȂ�Ƃ����_�ɒ��ӂ��Ă��������B |
|
378 | ||
379 |
�܂�execute�̃L���[�g�ȋ@�\�Ƃ��āASQL�̍Ō�ɃZ�~�R��������Ȃ��Ă� |
|
380 |
���܂��܂���B |
|
381 | ||
382 |
$dbi->execute('select * from book'); |
|
383 | ||
384 |
=head2 3. �s�̃t�F�b�` |
|
385 | ||
386 |
C<select()>���\�b�h�̖߂�l��L<DBIx::Custom::Result>�I�u�W�F�N�g�ł��B |
|
387 |
L<DBIx::Custom::Result>�ɂ͍s��t�F�b�`���邽�߂̂��܂��܂ȃ��\�b�h�� |
|
388 |
�p�ӂ���Ă��܂��B |
|
389 | ||
390 |
=head3 1�s�Ât�F�b�`(�z��) C<fetch()> |
|
391 | ||
392 |
��s�t�F�b�`���Ĕz��̃��t�@�����X�Ɋi�[����ɂ�C<fetch()>��g�p���܂��B |
|
added DBIx::Custom::Guides
|
393 | |
394 |
while (my $row = $result->fetch) { |
|
update pod
|
395 |
my $title = $row->[0]; |
396 |
my $author = $row->[1]; |
|
added DBIx::Custom::Guides
|
397 |
} |
398 | ||
update pod
|
399 |
while���[�v��g��āA���ׂĂ̍s��擾���邱�Ƃ��ł��܂��B |
400 | ||
401 |
=head3 �ŏ��̍s�����t�F�b�`(�z��) C<fetch_first()> |
|
402 | ||
403 |
��s�����t�F�b�`���Ĕz��̃��t�@�����X�Ɋi�[����ɂ�C<fetch_first()> |
|
404 |
��g�p���܂��B |
|
added DBIx::Custom::Guides
|
405 | |
406 |
my $row = $result->fetch_first; |
|
407 | ||
update pod
|
408 |
��s�̃t�F�b�`���I������͂���ȏ�t�F�b�`�ł��Ȃ��Ȃ�܂��B |
409 |
���I�ɂ�1�s�̃t�F�b�`���I������� |
|
410 |
�X�e�[�g�����g�n���h����C<finish()>����s����܂��B |
|
added DBIx::Custom::Guides
|
411 | |
update pod
|
412 |
=head3 �����s��Ƀt�F�b�`(�z��) C<fetch_multi()> |
413 | ||
414 |
�����s��t�F�b�`���Ĕz��̃��t�@�����X��v�f�Ɏ��� |
|
415 |
�z��̃��t�@�����X�Ɋi�[����ɂ�C<fetch_multi()>��g�p���܂��B |
|
416 | ||
417 |
while (my $rows = $result->fetch_multi(2)) { |
|
418 |
my $title0 = $rows->[0][0]; |
|
419 |
my $author0 = $rows->[0][1]; |
|
420 |
|
|
421 |
my $title1 = $rows->[1][0]; |
|
422 |
my $author1 = $rows->[1][1]; |
|
added DBIx::Custom::Guides
|
423 |
} |
update pod
|
424 | |
425 |
��ɂ͎��o�������s����w�肵�܂��B |
|
426 | ||
427 |
�w�肵���s��i�[�������̂悤�ȃf�[�^��擾�ł��܂��B |
|
428 | ||
429 |
[ |
|
430 |
['Perl', 'Ken'], |
|
431 |
['Ruby', 'Mark'] |
|
432 |
] |
|
433 | ||
434 |
=head3 ���ׂĂ̍s��t�F�b�`(�z��) C<fetch_all> |
|
435 | ||
436 |
���ׂĂ̍s��t�F�b�`���Ĕz��̃��t�@�����X��v�f�Ɏ��� |
|
437 |
�z��̃��t�@�����X�Ɋi�[����ɂ�C<fetch_all()>��g�p���܂��B |
|
added DBIx::Custom::Guides
|
438 | |
439 |
my $rows = $result->fetch_all; |
|
440 | ||
update pod
|
441 |
���ׂĂ̍s��i�[�������̂悤�ȃf�[�^��擾�ł��܂��B |
442 | ||
443 |
[ |
|
444 |
['Perl', 'Ken'], |
|
445 |
['Ruby', 'Mark'] |
|
446 |
] |
|
447 | ||
448 |
=head3 1�s�Ât�F�b�`(�n�b�V��) C<fetch_hash()> |
|
449 | ||
450 |
��s�t�F�b�`���ăn�b�V���̃��t�@�����X�Ɋi�[����ɂ�C<fetch_hash()>��g�p���܂��B |
|
added DBIx::Custom::Guides
|
451 | |
452 |
while (my $row = $result->fetch_hash) { |
|
453 |
my $title = $row->{title}; |
|
454 |
my $author = $row->{author}; |
|
455 |
} |
|
456 | ||
update pod
|
457 |
=head3 �ŏ��̍s�����t�F�b�`(�n�b�V��) C<fetch_hash_first()> |
458 | ||
459 |
��s�����t�F�b�`���ăn�b�V���̃��t�@�����X�Ɋi�[����ɂ� |
|
460 |
C<fetch_hash_first()>��g�p���܂��B |
|
added DBIx::Custom::Guides
|
461 | |
462 |
my $row = $result->fetch_hash_first; |
|
update pod
|
463 | |
464 |
��s�̃t�F�b�`���I������͂���ȏ�t�F�b�`�ł��Ȃ��Ȃ�܂��B |
|
465 |
���I�ɂ�1�s�̃t�F�b�`���I������� |
|
466 |
�X�e�[�g�����g�n���h����C<finish()>����s����܂��B |
|
467 | ||
468 |
=head3 �����s��Ƀt�F�b�`(�n�b�V��) C<fetch_hash_multi()> |
|
469 | ||
470 |
�����s��t�F�b�`���ăn�b�V���̃��t�@�����X��v�f�Ɏ��� |
|
471 |
�z��̃��t�@�����X�Ɋi�[����ɂ�C<fetch_hash_multi()> |
|
472 |
��g�p���܂��B |
|
added DBIx::Custom::Guides
|
473 | |
474 |
while (my $rows = $result->fetch_hash_multi(5)) { |
|
update pod
|
475 |
my $title0 = $rows->[0]{title}; |
476 |
my $author0 = $rows->[0]{author}; |
|
477 |
my $title1 = $rows->[1]{title}; |
|
478 |
my $author1 = $rows->[1]{author}; |
|
added DBIx::Custom::Guides
|
479 |
} |
update pod
|
480 | |
481 |
��ɂ͎��o�������s����w�肵�܂��B |
|
482 | ||
483 |
�w�肵���s��i�[�������̂悤�ȃf�[�^��擾�ł��܂��B |
|
484 | ||
485 |
[ |
|
486 |
{title => 'Perl', author => 'Ken'}, |
|
487 |
{title => 'Ruby', author => 'Mark'} |
|
488 |
] |
|
489 | ||
490 |
=head3 ���ׂĂ̍s��t�F�b�`(�n�b�V��) C<fetch_hash_all()> |
|
491 | ||
492 |
���ׂĂ̍s��t�F�b�`���ăn�b�V���̃��t�@�����X��v�f�Ɏ��� |
|
493 |
�z��̃��t�@�����X�Ɋi�[����ɂ�C<fetch_hash_all()> |
|
494 |
��g�p���܂��B |
|
added DBIx::Custom::Guides
|
495 | |
496 |
my $rows = $result->fetch_hash_all; |
|
497 | ||
update pod
|
498 |
���ׂĂ̍s��i�[�������̂悤�ȃf�[�^��擾�ł��܂��B |
499 | ||
500 |
[ |
|
501 |
{title => 'Perl', author => 'Ken'}, |
|
502 |
{title => 'Ruby', author => 'Mark'} |
|
503 |
] |
|
504 | ||
505 |
=head3 �X�e�[�g�����g�n���h�� C<sth()> |
|
506 | ||
507 |
�X�e�[�g�����g�n���h���ɒ��ڃA�N�Z�X�������ꍇ�� |
|
508 |
<sth>�Ŏ擾���邱�Ƃ��ł��܂��B |
|
added DBIx::Custom::Guides
|
509 | |
510 |
my $sth = $result->sth; |
|
511 | ||
update pod
|
512 |
�t�F�b�`�̃p�t�H�[�}���X���p�������Ȃ��Ƃ��ɂ́A |
513 |
�X�e�[�g�����g�n���h������ |
|
514 |
���p�ł��鑬�x�̑������\�b�h�𗘗p���邱�Ƃ��ł��܂��B |
|
515 | ||
516 |
=head2 4. �t�B���^�����O |
|
517 | ||
518 |
�f�[�^�x�[�X�Ƀf�[�^��o�^����Ƃ���f�[�^�x�[�X����f�[�^��擾���� |
|
519 |
�Ƃ��Ɏ����I�ɒl�̕ϊ���s�������ꍇ�������Ǝv���܂��B |
|
520 |
���Ƃ��A��t��\�������̏ꍇ�́A |
|
521 |
�f�[�^�x�[�X�ɓo�^����ꍇ��L<Time::Piece>�I�u�W�F�N�g���� |
|
522 |
�f�[�^�x�[�X�̓�t�̃t�H�[�}�b�g�ɁA |
|
523 |
�f�[�^�x�[�X����f�[�^��擾����Ƃ��́A���̋t��s����ƕ֗��ł��B |
|
524 | ||
525 |
=head3 �t�B���^�̓o�^ C<register_filter()> |
|
526 | ||
527 |
�t�B���^��o�^����ɂ�C<register_filter()>��g�p���܂��B |
|
528 | ||
529 |
$dbi->register_filter( |
|
530 |
# Time::Piece object to DATE format |
|
531 |
tp_to_date => sub { |
|
532 |
my $date = shift; |
|
533 | ||
534 |
return '0000-00-00' unless $tp; |
|
535 |
return $tp->strftime('%Y-%m-%d'); |
|
536 |
}, |
|
537 |
|
|
538 |
# DATE to Time::Piece object |
|
539 |
date_to_tp => sub { |
|
540 |
my $date = shift; |
|
541 | ||
542 |
return if $date eq '0000-00-00'; |
|
543 |
return Time::Piece->strptime($date, '%Y-%m-%d'); |
|
544 |
}, |
|
545 |
); |
|
added DBIx::Custom::Guides
|
546 | |
update pod
|
547 |
�o�^�����t�B���^��C<apply_filter()>�Ȃǂŗ��p���邱�Ƃ��ł��܂��B |
added DBIx::Custom::Guides
|
548 | |
update pod
|
549 |
=head3 �t�B���^�̓K�p C<apply_filter()> |
added DBIx::Custom::Guides
|
550 | |
update pod
|
551 |
�쐬�����t�B���^��K�p����ɂ́AC<apply_filter()>��g�p���܂��B |
552 | ||
553 |
$dbi->apply_filter('book', |
|
554 |
issue_date => {out => 'tp_to_date', in => 'date_to_tp'}, |
|
555 |
first_issue_date => {out => 'tp_to_date', in => 'date_to_tp'} |
|
added DBIx::Custom::Guides
|
556 |
); |
557 | ||
update pod
|
558 |
����̓e�[�u�����ł��B����ȍ~�́A�ƃt�B���^���[���̃y�A��L�q���܂��B |
559 |
�t�B���^���[����out�ɂ́A�f�[�^�x�[�X�Ƀf�[�^�𑗐M����Ƃ��ɓK�p����t�B���^��A |
|
560 |
�t�B���^���[����in�ɂ́A�f�[�^�x�[�X����f�[�^��擾����Ƃ��ɓK�p����t�B���^�� |
|
561 |
�L�q���܂��Bout���f�[�^�x�[�X�ɑ��M������Ain���f�[�^�x�[�X������o�����ł��B |
|
562 |
�t�B���^�ɂ́AC<register_filter>�œo�^�����t�B���^���̑��ɁA�R�[�h���t�@�����X�� |
|
563 |
�w�肷�邱�Ƃ�ł��܂��B |
|
564 | ||
565 |
issue_date => {out => sub { ... }, in => sub { ... }} |
|
566 | ||
567 |
�K�p���ꂽ�t�B���^��C<insert()>�AC<update()>�AC<update_all()>�AC<delete()>�A |
|
568 |
C<delete_all()>�AC<select()>�ŗL��ɂȂ�܂��B |
|
569 | ||
570 |
my $tp = Time::Piece->strptime('2010/10/14', '%Y/%m/%d'); |
|
571 |
my $result = $dbi->select(table => 'book', where => {issu_date => $tp}); |
|
572 | ||
573 |
�f�[�^�x�[�X�Ƀf�[�^�����M�����Ƃ��ɁAL<Time::Piece>�I�u�W�F�N�g�� |
|
574 |
�f�[�^�x�[�X�̓�t�̃t�H�[�}�b�g�u2010-10-14�v�ɕϊ�����܂��B |
|
575 | ||
576 |
�܂��t�Ƀf�[�^��t�F�b�`����Ƃ��ɂ́A�f�[�^�x�[�X�̓�t�̃t�H�[�}�b�g�� |
|
577 |
�^�C���s�[�X�I�u�W�F�N�g�ɕϊ�����܂��B |
|
578 | ||
579 |
my $row = $resutl->fetch_hash_first; |
|
580 |
my $tp = $row->{issue_date}; |
|
581 | ||
582 |
���̂悤�Ȏ����I�Ɏ�s�����t�B���^��o�^�ł��邱�Ƃ�L<DBIx::Custom>�� |
|
583 |
����̂ЂƂł��B |
|
added DBIx::Custom::Guides
|
584 | |
update pod
|
585 |
C<apply_filter()>�œK�p���ꂽ�t�B���^�̓e�[�u�������܂ޗɑ��Ă�L��ł��B |
586 | ||
587 |
$dbi->select( |
|
588 |
table => 'book', |
|
589 |
where => {'book.title' => 'Perl', 'book.author' => 'Ken'} |
|
590 |
); |
|
591 | ||
592 |
�e�[�u�����ʂ���K�v������Ƃ��ɕ֗��ȋ@�\�ł��B |
|
593 | ||
594 |
=head3 �ʂ̃t�B���^�̓K�p C<filter> |
|
595 | ||
596 |
C<apply_filter()>��g��čŏ��ɂ��ׂẴe�[�u���̗�ɂ��� |
|
597 |
�t�B���^���`���邱�Ƃ�ł��܂����A |
|
598 |
�ʂɃt�B���^��K�p���邱�Ƃ�ł��܂��B |
|
599 |
�ʂ̃t�B���^��C<apply_filter()>�œK�p�����t�B���^��㏑���܂��B |
|
600 |
�ʂ̃t�B���^��SQL��as��g��āA��̕ʖ���쐬����K�v������ꍇ�Ɋ��܂��B |
|
601 | ||
602 |
�f�[�^�x�[�X�ɑ��M����ꍇ�ɁA�ʂ̃t�B���^��K�p����ɂ́A�e���\�b�h�� |
|
603 |
C<filter>�I�v�V������g�p���܂��B�ʂ̃t�B���^�́AC<insert()>�AC<update()>�A |
|
604 |
C<update_all()>�AC<delete()>�AC<delete_all()>�AC<select()>�AC<execute()> |
|
605 |
�Ŏg�p���邱�Ƃ��ł��܂��B |
|
606 | ||
607 |
C<insert()>�̗����܂��B |
|
608 | ||
609 |
$dbi->insert( |
|
610 |
table => 'book', |
|
611 |
param => {issue_date => $tp, first_issue_date => $tp}, |
|
612 |
filter => {issue_date => 'tp_to_date', first_issue_date => 'tp_to_date'} |
|
613 |
); |
|
added DBIx::Custom::Guides
|
614 | |
update pod
|
615 |
C<execute()>�̗����܂��B |
616 | ||
617 |
my $sql = <<"EOS"; |
|
618 |
select YEAR(issue_date) as issue_year |
|
619 |
from book |
|
620 |
where YEAR(issue_date) = {? issue_year} |
|
621 |
EOS |
|
622 |
|
|
added DBIx::Custom::Guides
|
623 |
my $result = $dbi->execute( |
update pod
|
624 |
$sql, |
625 |
param => {issue_year => '2010'}, |
|
626 |
filter => {issue_year => 'tp_to_year'} |
|
added DBIx::Custom::Guides
|
627 |
); |
628 | ||
update pod
|
629 |
�����C<filter>��g���ǂ������ł��Bissue_date�̕ϊ��ɂ��Ă�C<apply_filter()> |
630 |
�œo�^���Ă���̂ł����A�V�����쐬������ł���issue_year�ɂ��ẮA |
|
631 |
���̕ϊ���o�^����Ă��܂���B�ł��̂ŁA�ʂɃt�B���^��ݒ肵�Ă��܂��B |
|
added DBIx::Custom::Guides
|
632 | |
update pod
|
633 |
�܂����ɍs��t�F�b�`����Ƃ��ɂ�ʂ̃t�B���^��K�p���邱�Ƃ��ł��܂��B |
634 |
�t�B���^��K�p����ɂ́A |
|
635 |
C<DBIx::Custom::Result>�N���X��C<filter>���\�b�h��g�p���܂��B |
|
added DBIx::Custom::Guides
|
636 | |
update pod
|
637 |
$result->filter(issue_year => 'year_to_tp'); |
added DBIx::Custom::Guides
|
638 | |
update pod
|
639 |
�p�ɂɗ��p����̂ł���A�ʂɓo�^�������C<apply_filter()>�œo�^ |
640 |
���Ă������ق����֗��ł��傤�BC<apply_filter()>�͑��݂��Ȃ���ɑ��Ă� |
|
641 |
�t�B���^��K�p�ł��邩��ł��B |
|
642 | ||
643 |
$dbi->apply_filter('book', |
|
644 |
'issue_year' => {out => 'tp_to_year', in => 'year_to_tp'} |
|
645 |
); |
|
646 | ||
647 |
=head3 �ŏI�o�͂̂��߂̃t�B���^�����O C<end_filter()> |
|
648 | ||
649 |
C<DBIx::Custom::Result>�ł͂���ɍŌ�ɂ���x�A�t�B���^��lj�� |
|
650 |
�o�^���邱�Ƃ��ł��܂��B���Ƃ���HTML�ɏo�͂������ꍇ�ɁATime::Piece |
|
651 |
�I�u�W�F�N�g����ǂ݂₷���L�q�ɕϊ����邱�Ƃ��ł��܂��B |
|
652 |
�Ō�̃t�B���^��o�^����ɂ́AC<end_filter()>��g�p���܂��B |
|
653 | ||
654 |
$result->end_filter(issue_date => sub { |
|
655 |
my $tp = shift; |
|
656 |
|
|
657 |
return '' unless $tp; |
|
658 |
return $tp->strftime('%Y/%m/%d %h:%m:%s (%a)'); |
|
659 |
}); |
|
660 | ||
661 |
��t��₷���`�Ƀt�H�[�}�b�g���邱�Ƃ��ł��܂��B |
|
662 | ||
663 |
�t�B���^�̓t�F�b�`��s���O�ɓo�^���Ă����K�v�����邱�Ƃ� |
|
664 |
���ӂ��Ă��������B |
|
665 | ||
666 |
$result->filter(...); |
|
667 |
$result->end_filter(...); |
|
668 |
my $row = $result->fetch_hash_first; |
|
669 | ||
670 |
=head3 ��̏���Ƀt�B���^��K�p���� C<each_column()> |
|
671 | ||
672 |
��t�^�̗�͎蓮�Őݒ肵�Ȃ��Ă�A�����I�ɐݒ�ł���ƕ֗��ł��B |
|
673 |
���̂��߂Ƀf�[�^�x�[�X�̃e�[�u���̗�̂��ׂĂ̏��� |
|
674 |
���Ԃɏ������邽�߂�C<each_column()>������܂��B |
|
675 | ||
676 |
$dbi->each_column( |
|
677 |
sub { |
|
678 |
my ($self, $table, $column, $info) = @_; |
|
679 |
|
|
680 |
my $type = $info->{TYPE_NAME}; |
|
681 |
|
|
682 |
my $filter = $type eq 'DATE' ? {out => 'tp_to_date', in => 'date_to_tp'} |
|
683 |
: $type eq 'DATETIME' ? {out => 'tp_to_datetime', in => 'datetime_to_tp'} |
|
684 |
: undef; |
|
685 |
|
|
686 |
$self->apply_filter($table, $column, $filter) |
|
687 |
if $filter; |
|
688 |
} |
|
689 |
); |
|
690 | ||
691 |
each_column�̓R�[���o�b�N����܂��B�R�[���o�b�N�̈�� |
|
692 |
���Ԃ�L<DBIx::Custom>�I�u�W�F�N�g�A�e�[�u�����A�A��̏��ł��B |
|
693 |
��̌^���̏����ƂɎ����I�ɁA�t�B���^��K�p���Ă��܂��B |
|
694 | ||
695 |
�ЂƂ̒��ӓ_�Ƃ��ăR�[���o�b�N�̒�����A�R�[���o�b�N�̊O�� |
|
696 |
�̕ϐ���Q�Ƃ��Ȃ��悤�ɒ��ӂ��Ă��������Beach_column�� |
|
697 |
���X1����s����邾���Ȃ̂ŁA�قƂ�ǂ̏ꍇ��肠��܂��A |
|
698 |
�z�Q�Ƃɂ�郁�������[�N���������Ă��܂��\�����Ă��邩��ł��B |
|
699 | ||
700 |
=head2 5. �^�O |
|
701 | ||
702 |
=head3 �^�O�̋@�\ |
|
703 | ||
704 |
L<DBIx::Custom>��SQL�̒��Ƀ^�O�ߍ��ދ@�\���Ă��܂��B |
|
705 | ||
706 |
select * from book where {= title} and {like author}; |
|
707 | ||
708 |
{= title}��{like author}�̕������^�O�ł��B�^�O�͎��̂悤�Ȍ`�� |
|
709 |
����܂��B |
|
710 | ||
711 |
{�^�O�� ��1 ��2 ...} |
|
added DBIx::Custom::Guides
|
712 |
|
update pod
|
713 |
�^�O��C<{>�Ŏn�܂�AC<}>�ŏI���܂��B�ŏ���C<{>�ƃ^�O���̊� |
714 |
�ɂ͋�}��Ȃ��悤���ӂ��Ă��������B |
|
715 | ||
716 |
�^�O�̋@�\�̂��߂�C<{>��C<}>�͗\���ɂȂ�Ă��܂��B |
|
717 |
�����p�������ꍇ�͒��O��\����ăG�X�P�[�v��s���K�v������܂��B |
|
718 | ||
719 |
select from book \\{ ... \\} |
|
720 | ||
721 |
C<\>���̂�Perl�̃G�X�P�[�v�����ł��̂ŁA |
|
722 |
�G�X�P�[�v����ꍇ��C<\>����K�v�ɂȂ�Ƃ����_�ɒ��ӂ��Ă��������B |
|
723 | ||
724 |
��L�̃^�O��SQL����s�����O�Ɏ���SQL�ɓW�J����܂��B |
|
725 | ||
726 |
select * from book where title = ? and author like ?; |
|
727 | ||
728 |
�^�O��܂�SQL���s����ɂ�C<execute()>��g�p���܂��B |
|
729 | ||
730 |
my $sql = "select * from book where {= author} and {like title};" |
|
731 |
$dbi->execute($sql, param => {title => 'Perl', author => '%Ken%'}); |
|
732 | ||
733 |
C<param>�I�v�V������g��āA�v���[�X�z���_�ɖ��ߍ��݂����l�� |
|
734 |
�n�b�V�����t�@�����X�Ŏw�肷�邱�Ƃ��ł��܂��B |
|
735 | ||
736 |
���̃��\�b�h�Ɠ��l��C<execute()>�ɂ����Ă�C<filter>��w�肷�邱�Ƃ��ł��܂��B |
|
737 | ||
738 |
$dbi->execute($sql, param => {title => 'Perl', author => '%Ken%'} |
|
739 |
filter => {title => 'to_something'); |
|
740 | ||
741 |
C<execute>�̂ЂƂ̒��ӓ_�Ƃ��Ă�C<apply_filter()>�œK�p���ꂽ�t�B���^ |
|
742 |
�̓f�t�H���g�ł͗L��ł͂Ȃ��Ƃ������Ƃɒ��ӂ��Ă��������B |
|
743 |
C<apply_filter()>�œK�p���ꂽ�t�B���^��L��ɂ���ɂ́A |
|
744 |
C<table>��w�肷��K�v������܂��B |
|
745 | ||
746 |
$dbi->execute($sql, param => {title => 'Perl', author => '%Ken%'} |
|
747 |
table => ['book']); |
|
748 | ||
749 |
=head2 �^�O�ꗗ |
|
750 | ||
751 |
L<DBIx::Custom>�ł͎��̃^�O���g�p�\�ł��B |
|
752 | ||
753 |
���̂悤�Ƀ^�O��g���SQL����\������̂�L<DBIx::Custom>�� |
|
754 |
����ł��B�ȉ��̃^�O�����p�\�ł��B |
|
755 | ||
756 |
=head3 C<?> |
|
757 | ||
758 |
C<?>�^�O�͈ȉ��̂悤�ɓW�J����܂��B |
|
759 | ||
760 |
{? NAME} -> ? |
|
761 | ||
762 |
=head3 C<=> |
|
763 | ||
764 |
C<=>�^�O�͈ȉ��̂悤�ɓW�J����܂��B |
|
765 | ||
766 |
{= NAME} -> NAME = ? |
|
767 | ||
768 |
=head3 C<E<lt>E<gt>> |
|
769 | ||
770 |
C<E<lt>E<gt>>�^�O�͈ȉ��̂悤�ɓW�J����܂��B |
|
771 | ||
772 |
{<> NAME} -> NAME <> ? |
|
773 | ||
774 |
=head3 C<E<lt>> |
|
775 | ||
776 |
C<E<lt>>�^�O�͈ȉ��̂悤�ɓW�J����܂��B |
|
777 | ||
778 |
{< NAME} -> NAME < ? |
|
779 | ||
780 |
=head3 C<E<gt>> |
|
781 | ||
782 |
C<E<gt>>�^�O�͈ȉ��̂悤�ɓW�J����܂��B |
|
783 | ||
784 |
{> NAME} -> NAME > ? |
|
785 | ||
786 |
=head3 C<E<gt>=> |
|
787 | ||
788 |
C<E<gt>=>�^�O�͈ȉ��̂悤�ɓW�J����܂��B |
|
789 | ||
790 |
{>= NAME} -> NAME >= ? |
|
791 | ||
792 |
=head3 C<E<lt>=> |
|
793 | ||
794 |
C<E<lt>=>�^�O�͈ȉ��̂悤�ɓW�J����܂��B |
|
795 | ||
796 |
{<= NAME} -> NAME <= ? |
|
797 | ||
798 |
=head3 C<like> |
|
799 | ||
800 |
C<like>�^�O�͈ȉ��̂悤�ɓW�J����܂��B |
|
801 | ||
802 |
{like NAME} -> NAME like ? |
|
803 | ||
804 |
=head3 C<in> |
|
805 | ||
806 |
C<in>�^�O�͈ȉ��̂悤�ɓW�J����܂��B�v���[�X�z���_�� |
|
807 |
�����Ŏw�肷��K�v�����邱�Ƃɒ��ӂ��Ă��������B |
|
808 | ||
809 |
{in NAME COUNT} -> NAME in [?, ?, ..] |
|
810 | ||
811 |
=head3 C<insert_param> |
|
812 | ||
813 |
C<insert_param>�^�O�͈ȉ��̂悤�ɓW�J����܂��B |
|
814 | ||
added DBIx::Custom::Guides
|
815 |
{insert_param NAME1 NAME2} -> (NAME1, NAME2) values (?, ?) |
update pod
|
816 | |
817 |
=head3 C<update_param> |
|
818 | ||
819 |
C<update_param>�^�O�͈ȉ��̂悤�ɓW�J����܂��B |
|
820 | ||
added DBIx::Custom::Guides
|
821 |
{update_param NAME1 NAME2} -> set NAME1 = ?, NAME2 = ? |
822 | ||
update pod
|
823 |
=head2 �����̗�̈��� |
added DBIx::Custom::Guides
|
824 | |
update pod
|
825 |
�����̗��܂ރ^�O������ꍇ�ɂ�ASQL���s���邱�Ƃ��ł��܂��B |
826 |
���Ƃ��A��̓�t�Ŕ�r���Ȃ���Ȃ�Ȃ��ꍇ�� |
|
827 |
�l���Č��܂��傤�B |
|
added DBIx::Custom::Guides
|
828 | |
update pod
|
829 |
my $sql = "select * from table where {> date} and {< date};"; |
added DBIx::Custom::Guides
|
830 | |
update pod
|
831 |
���̂悤�ȏꍇ�͑Ή�����p�����[�^�̒l��z��̃��t�@�����X�ɂ��܂��B |
added DBIx::Custom::Guides
|
832 | |
update pod
|
833 |
my $dbi->execute($sql, param => {date => ['2010-10-01', '2012-02-10']}); |
added DBIx::Custom::Guides
|
834 | |
update pod
|
835 |
=head2 �^�O�̒lj� C<register_tag()> |
836 | ||
837 |
L<DBIx::Custom>�ł̓^�O��Ǝ��ɒlj���邱�Ƃ��ł��܂��B |
|
838 |
�^�O��lj����ɂ�C<register_tag()>��g�p���܂��B |
|
839 | ||
840 |
$dbi->register_tag( |
|
841 |
'=' => sub { |
|
842 |
my $column = shift; |
|
843 |
|
|
844 |
return ["$column = ?", [$column]]; |
|
added DBIx::Custom::Guides
|
845 |
} |
846 |
); |
|
847 | ||
update pod
|
848 |
�����ł̓f�t�H���g��C<=>�^�O���ǂ̂悤�Ɏ������Ă��邩����Ă��܂��B |
849 |
�^�O��o�^������̈�̓^�O�̒��ɏ����ꂽ��ɂȂ�܂��B |
|
added experimental DBIx::Cus...
|
850 | |
update pod
|
851 |
{�^�O�� ��1 ��2} |
added experimental DBIx::Cus...
|
852 | |
update pod
|
853 |
C<=>�^�O�̏ꍇ�� |
cleanup
|
854 | |
update pod
|
855 |
{= title} |
added experimental DBIx::Cus...
|
856 | |
update pod
|
857 |
�Ƃ����`���ł�����A�T�u���[�`���ɂ�title�Ƃ����ЂƂ̗��킽��Ă��܂��B |
added experimental DBIx::Cus...
|
858 | |
update pod
|
859 |
�T�u���[�`���̖߂�l�ɂ͎��̌`���̔z��̃��t�@�����X��Ԃ��K�v������܂��B |
860 | ||
861 |
[ |
|
862 |
�W�J��̕�����, |
|
863 |
[�v���[�X�z���_�ɖ��ߍ��݂ɗ��p�����1, ��2, ...] |
|
864 |
] |
|
865 | ||
866 |
��ڂ̗v�f�͓W�J��̕�����ł��B���̗�ł� |
|
867 | ||
868 |
'title = ?' |
|
869 | ||
870 |
��Ԃ��K�v������܂��B |
|
871 | ||
872 |
��ڂ̗v�f�̓v���[�X�z���_�ɖ��ߍ��݂ɗ��p�����܂ޔz��� |
|
873 |
���t�@�����X�ł��B����̗�ł� |
|
874 | ||
875 |
['title'] |
|
876 | ||
877 |
��Ԃ��K�v������܂��B�����̃v���[�X�z���_��܂ޏꍇ�́A���̕����� |
|
878 |
�����ɂȂ�܂��BC<insert_param>�^�O��C<update_param>�^�O�� |
|
879 |
���̕�������ە����ɂȂ�Ă��܂��B |
|
880 | ||
881 |
��L��킹��� |
|
882 | ||
883 |
['title = ?', ['title']] |
|
added experimental DBIx::Cus...
|
884 |
|
update pod
|
885 |
��Ԃ��K�v������Ƃ������Ƃł��B |
added DBIx::Custom::Guides
|
886 | |
update pod
|
887 |
�^�O�̎���̑��̃T���v����L<DBIx::Custom::Tag>�̃\�[�X�R�[�h |
888 |
����ɂȂ�Ă݂Ă��������B |
|
added DBIx::Custom::Guides
|
889 | |
update pod
|
890 |
=head2 6. Where��̓��I�Ȑ��� |
891 | ||
892 |
=head3 Where��̓��I�Ȑ��� where() |
|
893 | ||
894 |
�����̌�����w�肵�āA�����s�������ꍇ������܂��B |
|
895 |
����3�̃P�[�X��where���l���Ă݂܂��傤�B |
|
896 |
���L�̂悤��where�傪�K�v�ɂȂ�܂��B |
|
897 | ||
898 |
title�̒l�����Ō�������ꍇ |
|
899 | ||
900 |
where {= title} |
|
901 | ||
902 |
author�̒l�����Ō�������ꍇ |
|
903 | ||
904 |
where {= author} |
|
905 | ||
906 |
title��author�̗���̒l�Ō�������ꍇ |
|
907 | ||
908 |
where {= title} and {=author} |
|
909 | ||
910 |
L<DBIx::Custom>�ł͓��I��Where��̐�����T�|�[�g���Ă��܂��B |
|
911 |
�܂�C<where()>��L<DBIx::Custom::Where>�I�u�W�F�N�g�����܂��B |
|
912 | ||
913 |
my $where = $dbi->where; |
|
914 | ||
915 |
����C<clause()>��g�p����where���L�q���܂��B |
|
916 | ||
917 |
$where->clause( |
|
918 |
['and', '{= title'}, '{= author}'] |
|
added DBIx::Custom::Guides
|
919 |
); |
920 | ||
update pod
|
921 |
clause�̎w���@�͎��̂悤�ɂȂ�܂��B |
922 | ||
923 |
['or' ���邢�� 'and', �^�O1, �^�O2, �^�O3] |
|
added DBIx::Custom::Guides
|
924 | |
update pod
|
925 |
����ɂ�or���邢��and��w�肵�܂��B����ȍ~�ɂ� |
926 |
������^�O��g��ċL�q���܂��B |
|
927 | ||
928 |
C<clause>�̎w��͓��q�ɂ��邱�Ƃ�ł��A����ɕ��G�ȏ� |
|
929 |
��L�q���邱�Ƃ�ł��܂��B |
|
930 | ||
931 |
['and', |
|
932 |
'{= title}', |
|
933 |
['or', '{= author}', '{like date}'] |
|
934 |
] |
|
935 | ||
936 |
���̂悤��C<clause>��ݒ肵�����C<param>�Ƀp�����[�^��w�肵�܂��B |
|
added DBIx::Custom::Guides
|
937 |
|
update pod
|
938 |
my $param => {title => 'Perl'}; |
939 |
$where->param($param); |
|
added DBIx::Custom::Guides
|
940 | |
update pod
|
941 |
���̗�ł�title�������p�����[�^�Ɋ܂܂�Ă��܂��B |
added DBIx::Custom::Guides
|
942 | |
update pod
|
943 |
���̌�C<to_string()>���s�����$param�Ɋ܂܂��p�����[�^���� |
944 |
where������邱�Ƃ��ł��܂��B |
|
945 | ||
946 |
my $where_clause = $where->to_string; |
|
947 | ||
948 |
�p�����[�^��title�����ł��̂ŁA���̂悤��where�傪��������܂��B |
|
949 | ||
950 |
where {= title} |
|
951 | ||
952 |
�܂�L<DBIx::Custom>�͕�����̕]����I�[�o�[���[�h���āAC<to_string()> |
|
953 |
��Ăяo���悤�ɂ��Ă��܂��̂ŁA���̂悤�ɂ���where������邱�Ƃ� |
|
954 |
�ł��܂��B |
|
955 | ||
956 |
my $where_clause = "$where"; |
|
957 | ||
958 |
�����SQL�̒���where��ߍ��ނƂ��ɂƂĂ�𗧂@�\�ł��B |
|
added DBIx::Custom::Guides
|
959 | |
update pod
|
960 |
=head3 ����̗�܂ޏꍇ |
check arguments of connect m...
|
961 | |
update pod
|
962 |
�^�O�̒��ɓ���̖��O���̂����݂����ꍇ�ł��I�� |
963 |
where���쐬���邱�Ƃ��ł��܂��B |
|
added experimental DBIx::Cus...
|
964 | |
update pod
|
965 |
���Ƃ��A�p�����[�^�Ƃ��ĊJ�n��t�ƏI����t��������Ƃ� |
966 |
�l���Ă݂Ă��������B |
|
added experimental DBIx::Cus...
|
967 | |
update pod
|
968 |
my $param = {start_date => '2010-11-15', end_date => '2011-11-21'}; |
added experimental DBIx::Cus...
|
969 | |
update pod
|
970 |
�܂��J�n��t�ƏI����t�̕Е���A�ǂ������Ȃ��ꍇ���邩����܂���B |
added experimental DBIx::Cus...
|
971 | |
update pod
|
972 |
���̏ꍇ�͎��̂悤�ȃp�����[�^�ɕϊ����邱�ƂőΉ����邱�Ƃ��ł��܂��B |
973 | ||
974 |
my $p = {date => ['2010-11-15', '2011-11-21']}; |
|
975 | ||
976 |
�l���z��̃��t�@�����X�ɂȂ�Ă��邱�Ƃɒ��ڂ��Ă��������B���̂悤�ɂ���� |
|
977 |
�����̗��܂ރ^�O�ɏ��Ԃɖ��ߍ��ނ��Ƃ��ł��܂��B |
|
978 | ||
979 |
$where->clause( |
|
980 |
['and', '{> date}', '{< date}'] |
|
added experimental DBIx::Cus...
|
981 |
); |
update pod
|
982 |
$where->param($p); |
983 | ||
984 |
�܂��J�n��t�����݂��Ȃ��ꍇ�͎��̂悤�ȃf�[�^��쐬���܂��B |
|
985 | ||
986 |
my $p = {date => [$dbi->not_exists, '2011-11-21']}; |
|
987 | ||
988 |
L<DBIx::Custom>��C<not_exists>��DBIx::Custom::NotExists�I�u�W�F�N�g�� |
|
989 |
�擾�ł��܂��B����͑Ή�����l�����݂��Ȃ����Ƃ�����߂̂�̂ł��B |
|
990 | ||
991 |
�܂��I����t�����݂��Ȃ��ꍇ�͎��̂悤�ȃf�[�^��쐬���܂��B |
|
992 | ||
993 |
my $p = {date => ['2010-11-15']}; |
|
994 | ||
995 |
�ǂ�����݂��Ȃ��ꍇ�͎��̂悤�ȃf�[�^��쐬���܂��B |
|
996 | ||
997 |
my $p = {date => []}; |
|
998 | ||
999 |
��������̂ň�ԊȒP�ɍ쐬�ł��郍�W�b�N����Ă����܂��B |
|
1000 | ||
1001 |
my @date; |
|
1002 |
push @date, exists $param->{start_date} ? $param->{start_date} |
|
1003 |
: $dbi->not_exists; |
|
1004 |
push @date, $param->{end_date} if exists $param->{end_date}; |
|
1005 |
my $p = {date => \@date}; |
|
1006 | ||
1007 |
=head3 C<select()>�Ƃ̘A�g |
|
1008 | ||
1009 |
L<DBIx::Custom::Where>�I�u�W�F�N�g�� |
|
1010 |
C<select()>��C<where>�ɒ��ړn�����Ƃ� |
|
1011 |
�ł��܂��B |
|
1012 |
|
|
1013 |
my $where = $dbi->where; |
|
1014 |
$where->clause(...); |
|
1015 |
$where->param($param); |
|
1016 |
my $result = $dbi->select(table => 'book', where => $where); |
|
1017 | ||
1018 |
���邢��C<update()>�AC<delete()>��where�Ɏw�肷�邱�Ƃ�\�ł��B |
|
1019 | ||
1020 |
=head3 C<execute()>�Ƃ̘A�g |
|
1021 | ||
1022 |
C<execute()>�Ƃ̘A�g�ł��BSQL��쐬����Ƃ��ɖ��ߍ��ނ��Ƃ��ł��܂��B |
|
added experimental DBIx::Cus...
|
1023 | |
1024 | ||
update pod
|
1025 |
my $where = $dbi->where; |
1026 |
$where->clause(...); |
|
1027 |
$where->param($param); |
|
1028 | ||
1029 |
my $sql = <<"EOS" |
|
1030 |
select * from book; |
|
1031 |
$where |
|
1032 |
EOS |
|
1033 | ||
1034 |
$dbi->execute($sql, param => $param); |
|
1035 | ||
1036 |
=head2 7. �e�[�u�����f�� |
|
1037 | ||
1038 |
=head3 �e�[�u���I�u�W�F�N�g�̍쐬 C<table()> |
|
1039 | ||
1040 |
L<DBIx::Custom>�̓��W�b�N�Ƃ��ăe�[�u���𒆐S�ɂ����� |
|
1041 |
���f���̍쐬��x�����܂��B |
|
1042 | ||
1043 |
�A�v���P�[�V�����̃��W�b�N��L�q����Ƃ��ɁA���̃��W�b�N�� |
|
1044 |
�f�[�^�x�[�X�̃e�[�u���ɂ����邱�Ƃ́ARDBMS�𗘗p���� |
|
1045 |
���f���ł���A�R�[�h�̏d�����Ȃ� |
|
1046 |
�킩��₷����̂ɂȂ�܂��B |
|
1047 | ||
1048 |
�e�[�u���I�u�W�F�N�g������ɂ�C<table()>��g�p���܂��B |
|
1049 | ||
1050 |
my $table = $dbi->table('book'); |
|
1051 | ||
1052 |
��ۂɃf�[�^�x�[�X�Ƀe�[�u���͑��݂��Ă���K�v�͂���܂���B |
|
1053 |
����͉��z�I�ȃe�[�u���I�u�W�F�N�g�ł��B����� |
|
1054 |
L<DBIx::Customm::Table>�I�u�W�F�N�g�ɂȂ�܂��B |
|
1055 | ||
1056 |
�e�[�u���I�u�W�F�N�g�����C<insert()>�AC<update()>�AC<update_all()>�A |
|
1057 |
C<delete()>�AC<delete_all()>�AC<select()>�Ȃǂ̃��\�b�h�Ăяo�����Ƃ��ł��܂��B |
|
1058 |
L<DBIx::Custom>�ƈقȂ�Ƃ���́AC<table>��K������w�肷��K�v�� |
|
1059 |
�Ȃ��Ƃ������Ƃł��B |
|
1060 | ||
1061 |
$table->insert(param => $param); |
|
1062 | ||
1063 |
C<table���̒l�͎����I��book�ɐݒ肳��܂��B |
|
1064 | ||
1065 |
�܂��e�[�u���I�u�W�F�N�g�ɂ͓Ǝ��̃��\�b�h��lj���邱�Ƃ��ł��܂��B |
|
1066 | ||
1067 |
$table->method( |
|
1068 |
register => sub { |
|
added experimental DBIx::Cus...
|
1069 |
my $self = shift; |
update pod
|
1070 |
my $table_name = $self->name; |
1071 |
# something |
|
added experimental DBIx::Cus...
|
1072 |
}, |
update pod
|
1073 |
list => sub { |
1074 |
my $self = shift; |
|
1075 |
my $table_name = $self->name; |
|
1076 |
# something |
|
1077 |
} |
|
1078 |
); |
|
1079 | ||
1080 |
���\�b�h�ɓn���������L<DBIx::Custom::Table>�I�u�W�F�N�g�ł��B |
|
1081 |
C<name()>��g�p���āA�e�[�u������擾���邱�Ƃ��ł��܂��B |
|
1082 | ||
1083 |
���̂悤�ɂ��ēo�^�������\�b�h�͒��ڌĂяo�����Ƃ��ł��܂��B |
|
1084 | ||
1085 |
$table->register(...); |
|
1086 |
$table->list(...); |
|
1087 | ||
1088 |
�܂��e�[�u����p�̃��\�b�h��I�[�o�[���C�h���č쐬���邱�Ƃ�ł��܂��B |
|
1089 | ||
1090 |
$table->method( |
|
1091 |
insert => sub { |
|
added experimental DBIx::Cus...
|
1092 |
my $self = shift; |
1093 |
|
|
update pod
|
1094 |
$self->base_insert(...); |
1095 |
|
|
1096 |
# something |
|
added experimental DBIx::Cus...
|
1097 |
} |
1098 |
); |
|
1099 | ||
update pod
|
1100 |
��Ƃ�Ƒ��݂��Ă���C<insert()>��ĂԂɂ�C<base_$method>�Ƃ��܂��BL<DBIx::Custom::Table> |
1101 |
�̃I�[�o�[���C�h�̋@�\�͊ȈՓI�Ȃ�̂ł����A�ƂĂ�֗��ł��B |
|
added experimental DBIx::Cus...
|
1102 | |
update pod
|
1103 |
=head2 �e�[�u���ŋ��L�̃��\�b�h�̓o�^ |
added experimental DBIx::Cus...
|
1104 | |
update pod
|
1105 |
���ׂẴe�[�u���Ń��\�b�h��L����ɂ�C<table>���\�b�h�Ńe�[�u����쐬����O�ɁA |
1106 |
C<base_table>�Ƀ��\�b�h��o�^���Ă����܂��B |
|
added experimental DBIx::Cus...
|
1107 | |
update pod
|
1108 |
$dbi->base_table->method( |
1109 |
count => sub { |
|
1110 |
my $self = shift; |
|
1111 |
return $self->select(column => ['count(*)']); |
|
1112 |
} |
|
1113 |
); |
|
added DBIx::Custom::Guides
|
1114 | |
update pod
|
1115 |
�܂��e�[�u�������L<DBIx::Custom>��L<DBI>�̂��ׂẴ��\�b�h��Ăяo�����Ƃ��ł��܂��B |
added DBIx::Custom::Guides
|
1116 | |
update pod
|
1117 |
# DBIx::Custom method |
1118 |
$table->execute($sql); |
|
1119 |
|
|
1120 |
# DBI method |
|
1121 |
$table->begin_work; |
|
1122 |
$table->commit; |
|
1123 | ||
1124 |
=head2 ��ʓI�ȃ��f���̍\�� |
|
added DBIx::Custom::Guides
|
1125 | |
update pod
|
1126 |
��ʓI�ɂ́AL<DBIx::Custom>��p�����ăR���X�g���N�^�̒��ɁA���f����쐬 |
1127 |
����̂��悢�ł��傤�B |
|
added DBIx::Custom::Guides
|
1128 | |
update pod
|
1129 |
package MyDBI; |
1130 |
|
|
1131 |
use base 'DBIx::Custom'; |
|
added DBIx::Custom::Guides
|
1132 |
|
update pod
|
1133 |
sub connect { |
1134 |
my $self = shift->SUPER::connect(@_); |
|
1135 |
|
|
1136 |
$self->base_table->method( |
|
1137 |
... => sub { ... } |
|
1138 |
); |
|
1139 |
|
|
1140 |
$self->table('book')->method( |
|
1141 |
insert_multi => sub { ... }, |
|
1142 |
... => sub { ... } |
|
1143 |
); |
|
1144 |
|
|
1145 |
$self->table('company')->method( |
|
1146 |
... => sub { ... }, |
|
1147 |
); |
|
1148 |
} |
|
1149 | ||
1150 |
���̂悤�ɂ��Ē�`���Ă����A���̂悤�ɗ��p���邱�Ƃ��ł��܂��B |
|
1151 | ||
1152 |
my $dbi = MyDBI->connect(...); |
|
1153 |
$dbi->table('book')->insert_multi(...); |
|
1154 | ||
1155 |
=head2 8. �p�t�H�[�}���X�̉�P |
|
1156 | ||
1157 |
=head3 �N�G���̍쐬 |
|
1158 | ||
1159 |
��C<insert()>���\�b�h��g�p���ăC���T�[�g���s�����ꍇ�A |
|
1160 |
�K�v�ȃp�t�H�[�}���X���Ȃ��ꍇ�����邩����܂���B |
|
1161 |
C<insert()>���\�b�h�́ASQL���ƃX�e�[�g�����g�n���h���� |
|
1162 |
����쐬���邽�߂ł��B |
|
1163 | ||
1164 |
���̂悤�ȏꍇ�́AC<query>�I�v�V������w�肷�邱�ƂŁA |
|
1165 |
�N�G����擾���邱�Ƃ��ł��܂��B |
|
1166 | ||
1167 |
my $query = $dbi->insert(table => 'book', param => $param, query => 1); |
|
1168 | ||
1169 |
�܂�C<create_query()>���\�b�h��g��ĔC�ӂ�SQL�̃N�G����쐬 |
|
1170 |
���邱�Ƃ�ł��܂��B |
|
1171 | ||
added DBIx::Custom::Guides
|
1172 |
my $query = $dbi->create_query( |
update pod
|
1173 |
"insert into book {insert_param title author};"; |
added DBIx::Custom::Guides
|
1174 |
); |
1175 | ||
update pod
|
1176 |
�߂�l��L<DBIx::Custom::Query>�I�u�W�F�N�g�ł��B |
1177 |
���̃I�u�W�F�N�g��SQL���ƃp�����[�^�o�C���h���̗� |
|
1178 |
�ێ����Ă��܂��B�܂��X�e�[�g�����g�n���h����ێ����Ă��܂��B |
|
added DBIx::Custom::Guides
|
1179 | |
1180 |
{ |
|
remove DBIx::Custom::Model
|
1181 |
sql => 'insert into book (title, author) values (?, ?);', |
update pod
|
1182 |
columns => ['title', 'author'], |
1183 |
sth => $sth |
|
added DBIx::Custom::Guides
|
1184 |
} |
1185 | ||
update pod
|
1186 |
�N�G���I�u�W�F�N�g��g��ČJ��Ԃ���s����ɂ�C<execute()>��g�p���܂��B |
added DBIx::Custom::Guides
|
1187 |
|
remove DBIx::Custom::Model
|
1188 |
my $params = [ |
added DBIx::Custom::Guides
|
1189 |
{title => 'Perl', author => 'Ken'}, |
1190 |
{title => 'Good days', author => 'Mike'} |
|
1191 |
]; |
|
1192 |
|
|
update pod
|
1193 |
foreach my $param (@$paramss) { |
1194 |
$dbi->execute($query, table => 'book', param => $input); |
|
added DBIx::Custom::Guides
|
1195 |
} |
1196 | ||
update pod
|
1197 |
C<execute>���\�b�h�̑���ɃN�G���I�u�W�F�g��n�����Ƃ��ł��܂��B |
1198 |
C<insert()>���\�b�h�������ł��B |
|
added DBIx::Custom::Guides
|
1199 | |
update pod
|
1200 |
���ӓ_������������܂��B����̓p�����[�^�̐��͕K�������łȂ��Ă͂Ȃ�Ȃ� |
1201 |
�Ƃ������Ƃł��B�ŏ���3�̃p�����[�^������n�����̂ɁA���̎�s�ł� |
|
1202 |
��̃p�����[�^��n���Ɨ\��Ȃ����ʂɂȂ�܂��B����� |
|
1203 |
���I�ɐ������ꂽSQL�Ɋ܂܂��v���[�X�z���_�̐����قȂ邩��ł��B |
|
1204 |
�܂�C<execute()>�ɂ��Ă͎����I�ɂ̓t�B���^���L��ɂȂ�Ȃ��̂ŁA |
|
1205 |
C<table>��w�肷��K�v�̂��邱�Ƃɒ��ӂ��Ă��������B |
|
1206 |
�{���ɕK�v�ȏꍇ�������p���Ă��������B |
|
added DBIx::Custom::Guides
|
1207 | |
update pod
|
1208 |
=head2 9. ���̑��̋@�\ |
added DBIx::Custom::Guides
|
1209 | |
update pod
|
1210 |
=head3 ���\�b�h�̓o�^ |
added DBIx::Custom::Guides
|
1211 | |
update pod
|
1212 |
���\�b�h��o�^����ɂ�C<method()>��g�p���܂��B |
added DBIx::Custom::Guides
|
1213 | |
update pod
|
1214 |
$dbi->method( |
1215 |
update_or_insert => sub { |
|
1216 |
my $self = shift; |
|
1217 |
# something |
|
1218 |
}, |
|
1219 |
find_or_create => sub { |
|
1220 |
my $self = shift; |
|
1221 |
# something |
|
1222 |
} |
|
1223 |
); |
|
1224 | ||
1225 |
<method()>�œo�^�������\�b�h�� |
|
1226 |
L<DBIx::Custom>�I�u�W�F�N�g���璼�ڌĂяo�����Ƃ��ł��܂��B |
|
1227 | ||
1228 |
$dbi->update_or_insert; |
|
1229 |
$dbi->find_or_create; |
|
1230 | ||
1231 |
=head3 ���ʃN���X�̕ύX |
|
added DBIx::Custom::Guides
|
1232 | |
update pod
|
1233 |
�K�v�Ȃ�Ό��ʃN���X��ύX���邱�Ƃ��ł��܂��B |
added DBIx::Custom::Guides
|
1234 | |
update pod
|
1235 |
package MyResult; |
added DBIx::Custom::Guides
|
1236 |
use base 'DBIx::Custom::Result'; |
1237 |
|
|
1238 |
sub some_method { ... } |
|
1239 | ||
1240 |
1; |
|
1241 |
|
|
1242 |
package main; |
|
1243 |
|
|
update pod
|
1244 |
use MyResult; |
added DBIx::Custom::Guides
|
1245 |
|
1246 |
my $dbi = DBIx::Custom->connect(...); |
|
update pod
|
1247 |
$dbi->result_class('MyResult'); |
added DBIx::Custom::Guides
|
1248 | |
update pod
|
1249 |
=head3 �L���b�V���O |
added DBIx::Custom::Guides
|
1250 | |
update pod
|
1251 |
�^�O�̓W�J���SQL�̓p�t�H�[�}���X�̗��R�̂��߂ɃL���b�V������܂��B |
1252 |
�����C<chace>�Őݒ�ł��A�f�t�H���g�ł̓L���b�V����s���ݒ�ł��B |
|
added DBIx::Custom::Guides
|
1253 | |
update pod
|
1254 |
$dbi->cache(1); |
added DBIx::Custom::Guides
|
1255 | |
update pod
|
1256 |
�L���b�V����@��C<cache_method>�Ƀ��\�b�h��w�肷�邱�Ƃ� |
1257 |
�ύX���邱�Ƃ��ł��܂��B |
|
1258 |
�f�[�^�̕ۑ��Ǝ擾�̂��߂̃��\�b�h���`���܂��B |
|
added DBIx::Custom::Guides
|
1259 | |
update pod
|
1260 |
�f�t�H���g�ł͎��̂悤�Ƀ�������ɃL���b�V����s����̂ɂȂ�Ă��܂��B |
1261 | ||
1262 |
$dbi->cache_method(sub { |
|
1263 |
sub { |
|
added DBIx::Custom::Guides
|
1264 |
my $self = shift; |
update pod
|
1265 |
|
1266 |
$self->{_cached} ||= {}; |
|
1267 |
|
|
1268 |
if (@_ > 1) { |
|
1269 |
# Set |
|
1270 |
$self->{_cached}{$_[0]} = $_[1] |
|
1271 |
} |
|
1272 |
else { |
|
1273 |
# Get |
|
1274 |
return $self->{_cached}{$_[0]} |
|
1275 |
} |
|
added DBIx::Custom::Guides
|
1276 |
} |
update pod
|
1277 |
}); |
1278 |
|
|
1279 |
����L<DBIx::Custom>�I�u�W�F�N�g�ł��B |
|
1280 |
����̓^�O�̓W�J�����O��SQL�ł��B |
|
1281 |
��O��̓^�O�̓W�J���SQL�ł��B |
|
added DBIx::Custom::Guides
|
1282 | |
update pod
|
1283 |
�����ō쐬����ꍇ�͑�O�����݂����ꍇ�̓L���b�V����ݒ肵�A |
1284 |
���݂��Ȃ�����ꍇ�̓L���b�V����擾�������� |
|
1285 |
�����������B |
|
added DBIx::Custom::Guides
|
1286 | |
update pod
|
1287 |
=cut |
added DBIx::Custom::Guides
|
1288 | |
pod fix
|
1289 |
=head1 EXAMPLES |
1290 | ||
1291 |
L<DBIx::Custom Wiki|https://github.com/yuki-kimoto/DBIx-Custom/wiki> - Many useful examples |
|
add examples
|
1292 | |
added DBIx::Custom::Guides
|
1293 |
=cut |