packaging one directory
|
1 |
package DBIx::Custom::Result; |
updatedd pod
|
2 |
use Object::Simple -base; |
cleanup
|
3 | |
packaging one directory
|
4 |
use Carp 'croak'; |
cleanup
|
5 |
use DBIx::Custom::Util qw/_array_to_hash _subname/; |
packaging one directory
|
6 | |
sub module use DBIx::Custom ...
|
7 |
has [qw/dbi sth/], |
cleanup
|
8 |
stash => sub { {} }; |
cleanup
|
9 | |
- added DBIx::Custom::Result...
|
10 |
*all = \&fetch_hash_all; |
11 | ||
- added EXPERIMENTAL DBIx::C...
|
12 |
sub column { |
cleanup
|
13 |
my $self = shift; |
14 |
|
|
15 |
my $column = []; |
|
16 |
my $rows = $self->fetch_all; |
|
17 |
push @$column, $_->[0] for @$rows; |
|
18 |
return $column; |
|
- added EXPERIMENTAL DBIx::C...
|
19 |
} |
20 | ||
micro optimization
|
21 |
sub fetch { |
cleanup
|
22 |
my $self = shift; |
23 |
|
|
24 |
# Info |
|
25 |
$self->_cache unless $self->{_cache}; |
|
26 |
|
|
27 |
# Fetch |
|
28 |
my @row = $self->{sth}->fetchrow_array; |
|
29 |
return unless @row; |
|
30 |
|
|
31 |
# Type rule |
|
32 |
if ($self->{type_rule}->{from1} && !$self->{type_rule_off} && !$self->{type_rule1_off}) { |
|
33 |
my $from = $self->{type_rule}->{from1}; |
|
34 |
for my $type (keys %$from) { |
|
35 |
for my $column (@{$self->{_type_map}->{$type}}) { |
|
36 |
$row[$_] = $from->{$type}->($row[$_]) |
|
37 |
for @{$self->{_pos}{$column} || []}; |
|
38 |
} |
|
micro optimization
|
39 |
} |
cleanup
|
40 |
} |
41 |
if ($self->{type_rule}->{from2} && !$self->{type_rule_off} && !$self->{type_rule2_off}) { |
|
42 |
my $from = $self->{type_rule}->{from2}; |
|
43 |
for my $type (keys %$from) { |
|
44 |
for my $column (@{$self->{_type_map}->{$type}}) { |
|
45 |
$row[$_] = $from->{$type}->($row[$_]) |
|
46 |
for @{$self->{_pos}{$column} || []}; |
|
47 |
} |
|
micro optimization
|
48 |
} |
cleanup
|
49 |
} |
50 |
|
|
51 |
# Filter |
|
52 |
if (($self->{filter} || $self->{default_filter}) && !$self->{filter_off}) { |
|
53 |
my @columns = $self->{default_filter} ? keys %{$self->{_columns}} |
|
54 |
: keys %{$self->{filter}}; |
|
55 |
|
|
56 |
for my $column (@columns) { |
|
57 |
my $filter = exists $self->{filter}->{$column} ? $self->{filter}->{$column} |
|
58 |
: $self->{default_filter}; |
|
59 |
next unless $filter; |
|
60 |
$row[$_] = $filter->($row[$_]) |
|
61 |
for @{$self->{_pos}{$column} || []}; |
|
62 |
} |
|
63 |
} |
|
64 |
if ($self->{end_filter} && !$self->{filter_off}) { |
|
65 |
for my $column (keys %{$self->{end_filter}}) { |
|
66 |
next unless $self->{end_filter}->{$column}; |
|
67 |
$row[$_] = $self->{end_filter}->{$column}->($row[$_]) |
|
68 |
for @{$self->{_pos}{$column} || []}; |
|
69 |
} |
|
70 |
} |
|
71 | ||
72 |
return \@row; |
|
micro optimization
|
73 |
} |
74 | ||
75 |
sub fetch_hash { |
|
cleanup
|
76 |
my $self = shift; |
77 |
|
|
78 |
# Info |
|
79 |
$self->_cache unless $self->{_cache}; |
|
80 |
|
|
81 |
# Fetch |
|
82 |
return unless my $row = $self->{sth}->fetchrow_hashref; |
|
83 |
|
|
84 |
# Type rule |
|
85 |
if ($self->{type_rule}->{from1} && |
|
86 |
!$self->{type_rule_off} && !$self->{type_rule1_off}) |
|
87 |
{ |
|
88 |
my $from = $self->{type_rule}->{from1}; |
|
89 |
for my $type (keys %$from) { |
|
90 |
$from->{$type} and $row->{$_} = $from->{$type}->($row->{$_}) |
|
91 |
for @{$self->{_type_map}->{$type}}; |
|
micro optimization
|
92 |
} |
cleanup
|
93 |
} |
94 |
if ($self->{type_rule}->{from2} && |
|
95 |
!$self->{type_rule_off} && !$self->{type_rule2_off}) |
|
96 |
{ |
|
97 |
my $from = $self->{type_rule}->{from2}; |
|
98 |
for my $type (keys %{$self->{type_rule}->{from2}}) { |
|
99 |
$from->{$type} and $row->{$_} = $from->{$type}->($row->{$_}) |
|
100 |
for @{$self->{_type_map}->{$type}}; |
|
micro optimization
|
101 |
} |
cleanup
|
102 |
} |
103 |
# Filter |
|
104 |
if (($self->{filter} || $self->{default_filter}) && |
|
105 |
!$self->{filter_off}) |
|
106 |
{ |
|
107 |
my @columns = $self->{default_filter} ? keys %{$self->{_columns}} |
|
108 |
: keys %{$self->{filter}}; |
|
109 |
|
|
110 |
for my $column (@columns) { |
|
111 |
next unless exists $row->{$column}; |
|
112 |
my $filter = exists $self->{filter}->{$column} ? $self->{filter}->{$column} |
|
113 |
: $self->{default_filter}; |
|
114 |
$row->{$column} = $filter->($row->{$column}) if $filter; |
|
115 |
} |
|
116 |
} |
|
117 |
if ($self->{end_filter} && !$self->{filter_off}) { |
|
118 |
exists $self->{_columns}{$_} && $self->{end_filter}->{$_} and |
|
119 |
$row->{$_} = $self->{end_filter}->{$_}->($row->{$_}) |
|
120 |
for keys %{$self->{end_filter}}; |
|
121 |
} |
|
122 |
$row; |
|
micro optimization
|
123 |
} |
124 | ||
cleanup
|
125 |
sub fetch_all { |
cleanup
|
126 |
my $self = shift; |
127 |
|
|
128 |
# Fetch all rows |
|
129 |
my $rows = []; |
|
130 |
while(my $row = $self->fetch) { push @$rows, $row} |
|
131 |
|
|
132 |
return $rows; |
|
cleanup
|
133 |
} |
134 | ||
135 |
sub fetch_hash_all { |
|
cleanup
|
136 |
my $self = shift; |
137 |
|
|
138 |
# Fetch all rows as hash |
|
139 |
my $rows = []; |
|
140 |
while(my $row = $self->fetch_hash) { push @$rows, $row } |
|
141 |
|
|
142 |
return $rows; |
|
cleanup
|
143 |
} |
144 | ||
- renamed DBIx::Custom::Resu...
|
145 |
sub fetch_hash_one { |
cleanup
|
146 |
my $self = shift; |
147 |
|
|
148 |
# Fetch hash |
|
149 |
my $row = $self->fetch_hash; |
|
150 |
return unless $row; |
|
151 |
|
|
152 |
# Finish statement handle |
|
153 |
$self->sth->finish; |
|
154 |
|
|
155 |
return $row; |
|
packaging one directory
|
156 |
} |
157 | ||
renamed fetch_rows to fetch_...
|
158 |
sub fetch_hash_multi { |
cleanup
|
159 |
my ($self, $count) = @_; |
160 |
|
|
161 |
# Fetch multiple rows |
|
162 |
croak 'Row count must be specified ' . _subname |
|
163 |
unless $count; |
|
164 |
|
|
165 |
return if $self->{_finished}; |
|
166 | ||
167 |
my $rows = []; |
|
168 |
for (my $i = 0; $i < $count; $i++) { |
|
169 |
my $row = $self->fetch_hash; |
|
170 |
unless ($row) { |
|
171 |
$self->{_finished} = 1; |
|
172 |
last; |
|
packaging one directory
|
173 |
} |
cleanup
|
174 |
push @$rows, $row; |
175 |
} |
|
176 |
|
|
177 |
return unless @$rows; |
|
178 |
return $rows; |
|
packaging one directory
|
179 |
} |
180 | ||
cleanup
|
181 |
sub fetch_multi { |
cleanup
|
182 |
my ($self, $count) = @_; |
183 |
|
|
184 |
# Row count not specifed |
|
185 |
croak 'Row count must be specified ' . _subname |
|
186 |
unless $count; |
|
187 |
|
|
188 |
return if $self->{_finished}; |
|
189 |
|
|
190 |
# Fetch multi rows |
|
191 |
my $rows = []; |
|
192 |
for (my $i = 0; $i < $count; $i++) { |
|
193 |
my $row = $self->fetch; |
|
194 |
unless ($row) { |
|
195 |
$self->{_finished} = 1; |
|
196 |
last; |
|
packaging one directory
|
197 |
} |
cleanup
|
198 |
push @$rows, $row; |
199 |
} |
|
200 |
|
|
201 |
return unless @$rows; |
|
202 |
return $rows; |
|
packaging one directory
|
203 |
} |
204 | ||
- renamed DBIx::Custom::Resu...
|
205 | |
206 |
sub fetch_one { |
|
cleanup
|
207 |
my $self = shift; |
208 |
|
|
209 |
# Fetch |
|
210 |
my $row = $self->fetch; |
|
211 |
return unless $row; |
|
212 |
|
|
213 |
# Finish statement handle |
|
214 |
$self->sth->finish; |
|
215 |
|
|
216 |
return $row; |
|
- renamed DBIx::Custom::Resu...
|
217 |
} |
218 | ||
added EXPERIMENTAL DBIx::Cus...
|
219 |
sub filter { |
220 |
my $self = shift; |
|
221 |
|
|
222 |
# Set |
|
223 |
if (@_) { |
|
224 |
|
|
225 |
# Convert filter name to subroutine |
|
226 |
my $filter = @_ == 1 ? $_[0] : [@_]; |
|
227 |
$filter = _array_to_hash($filter); |
|
228 |
for my $column (keys %$filter) { |
|
229 |
my $fname = $filter->{$column}; |
|
230 |
if (exists $filter->{$column} |
|
231 |
&& defined $fname |
|
232 |
&& ref $fname ne 'CODE') |
|
233 |
{ |
|
234 |
croak qq{Filter "$fname" is not registered" } . _subname |
|
235 |
unless exists $self->dbi->filters->{$fname}; |
|
236 |
$filter->{$column} = $self->dbi->filters->{$fname}; |
|
237 |
} |
|
238 |
} |
|
239 |
|
|
240 |
# Merge |
|
241 |
$self->{filter} = {%{$self->filter}, %$filter}; |
|
242 |
|
|
243 |
return $self; |
|
244 |
} |
|
245 |
|
|
246 |
return $self->{filter} ||= {}; |
|
247 |
} |
|
248 | ||
249 |
sub flat { |
|
250 |
my $self = shift; |
|
251 |
|
|
252 |
my @flat; |
|
253 |
while (my $row = $self->fetch) { |
|
254 |
push @flat, @$row; |
|
255 |
} |
|
256 |
return @flat; |
|
257 |
} |
|
258 | ||
added EXPERIMENTAL DBIx::Cus...
|
259 |
sub header { shift->sth->{NAME} } |
260 | ||
- renamed DBIx::Custom::Resu...
|
261 |
*one = \&fetch_hash_one; |
- added DBIx::Custom::Result...
|
262 | |
added EXPERIMENTAL DBIx::Cus...
|
263 |
sub type_rule { |
cleanup
|
264 |
my $self = shift; |
265 |
|
|
266 |
if (@_) { |
|
267 |
my $type_rule = ref $_[0] eq 'HASH' ? $_[0] : {@_}; |
|
268 | ||
269 |
# From |
|
270 |
for my $i (1 .. 2) { |
|
271 |
$type_rule->{"from$i"} = _array_to_hash($type_rule->{"from$i"}); |
|
272 |
for my $data_type (keys %{$type_rule->{"from$i"} || {}}) { |
|
273 |
croak qq{data type of from$i section must be lower case or number} |
|
274 |
if $data_type =~ /[A-Z]/; |
|
275 |
my $fname = $type_rule->{"from$i"}{$data_type}; |
|
276 |
if (defined $fname && ref $fname ne 'CODE') { |
|
277 |
croak qq{Filter "$fname" is not registered" } . _subname |
|
278 |
unless exists $self->dbi->filters->{$fname}; |
|
279 |
|
|
280 |
$type_rule->{"from$i"}{$data_type} = $self->dbi->filters->{$fname}; |
|
added EXPERIMENTAL DBIx::Cus...
|
281 |
} |
cleanup
|
282 |
} |
added EXPERIMENTAL DBIx::Cus...
|
283 |
} |
cleanup
|
284 |
$self->{type_rule} = $type_rule; |
added EXPERIMENTAL DBIx::Cus...
|
285 |
|
cleanup
|
286 |
return $self; |
287 |
} |
|
288 |
|
|
289 |
return $self->{type_rule} || {}; |
|
added EXPERIMENTAL DBIx::Cus...
|
290 |
} |
291 | ||
- changed EXPERIMENTAL DBIx:...
|
292 |
sub type_rule_off { |
cleanup
|
293 |
my $self = shift; |
294 |
$self->{type_rule_off} = 1; |
|
295 |
return $self; |
|
- changed EXPERIMENTAL DBIx:...
|
296 |
} |
297 | ||
298 |
sub type_rule_on { |
|
cleanup
|
299 |
my $self = shift; |
300 |
$self->{type_rule_off} = 0; |
|
301 |
return $self; |
|
- changed EXPERIMENTAL DBIx:...
|
302 |
} |
303 | ||
304 |
sub type_rule1_off { |
|
cleanup
|
305 |
my $self = shift; |
306 |
$self->{type_rule1_off} = 1; |
|
307 |
return $self; |
|
- changed EXPERIMENTAL DBIx:...
|
308 |
} |
309 | ||
310 |
sub type_rule1_on { |
|
cleanup
|
311 |
my $self = shift; |
312 |
$self->{type_rule1_off} = 0; |
|
313 |
return $self; |
|
- changed EXPERIMENTAL DBIx:...
|
314 |
} |
315 | ||
316 |
sub type_rule2_off { |
|
cleanup
|
317 |
my $self = shift; |
318 |
$self->{type_rule2_off} = 1; |
|
319 |
return $self; |
|
- changed EXPERIMENTAL DBIx:...
|
320 |
} |
321 | ||
322 |
sub type_rule2_on { |
|
cleanup
|
323 |
my $self = shift; |
324 |
$self->{type_rule2_off} = 0; |
|
325 |
return $self; |
|
- changed EXPERIMENTAL DBIx:...
|
326 |
} |
327 | ||
- added EXPERIMENTAL DBIx::C...
|
328 |
sub value { |
cleanup
|
329 |
my $self = shift; |
330 |
my $row = $self->fetch_one; |
|
331 |
my $value = $row ? $row->[0] : undef; |
|
332 |
return $value; |
|
- added EXPERIMENTAL DBIx::C...
|
333 |
} |
334 | ||
- fixed bug DBIx::Custom::Re...
|
335 |
sub _cache { |
cleanup
|
336 |
my $self = shift; |
337 |
$self->{_type_map} = {}; |
|
338 |
$self->{_pos} = {}; |
|
339 |
$self->{_columns} = {}; |
|
- removed EXPERIMENTAL statu...
|
340 |
for (my $i = 0; $i < @{$self->{sth}->{NAME} || []}; $i++) { |
cleanup
|
341 |
my $type = lc $self->{sth}{TYPE}[$i]; |
342 |
my $name = $self->{sth}{NAME}[$i]; |
|
343 |
$self->{_type_map}{$type} ||= []; |
|
344 |
push @{$self->{_type_map}{$type}}, $name; |
|
345 |
$self->{_pos}{$name} ||= []; |
|
346 |
push @{$self->{_pos}{$name}}, $i; |
|
347 |
$self->{_columns}{$name} = 1; |
|
348 |
} |
|
349 |
$self->{_cache} = 1; |
|
- fixed bug DBIx::Custom::Re...
|
350 |
} |
351 | ||
- renamed DBIx::Custom::Resu...
|
352 |
# DEPRECATED! |
353 |
sub fetch_hash_first { |
|
cleanup
|
354 |
my $self = shift; |
355 |
warn "DBIx::Custom::Result::fetch_hash_first is DEPRECATED! use fetch_hash_one instead"; |
|
356 |
return $self->fetch_hash_one(@_); |
|
- renamed DBIx::Custom::Resu...
|
357 |
} |
358 | ||
359 |
# DEPRECATED! |
|
360 |
sub fetch_first { |
|
cleanup
|
361 |
my $self = shift; |
362 |
warn "DBIx::Custom::Result::fetch_first is DEPRECATED! use fetch_one instead"; |
|
363 |
return $self->fetch_one(@_); |
|
- renamed DBIx::Custom::Resu...
|
364 |
} |
365 | ||
- DBIx::Custom::Result filte...
|
366 |
# DEPRECATED! |
367 |
sub filter_off { |
|
cleanup
|
368 |
warn "filter_off method is DEPRECATED!"; |
369 |
my $self = shift; |
|
370 |
$self->{filter_off} = 1; |
|
371 |
return $self; |
|
- DBIx::Custom::Result filte...
|
372 |
} |
373 | ||
374 |
# DEPRECATED! |
|
375 |
sub filter_on { |
|
cleanup
|
376 |
warn "filter_on method is DEPRECATED!"; |
377 |
my $self = shift; |
|
378 |
$self->{filter_off} = 0; |
|
379 |
return $self; |
|
- DBIx::Custom::Result filte...
|
380 |
} |
381 | ||
cleanup
|
382 |
# DEPRECATED! |
383 |
sub end_filter { |
|
cleanup
|
384 |
warn "end_filter method is DEPRECATED!"; |
385 |
my $self = shift; |
|
386 |
if (@_) { |
|
387 |
my $end_filter = {}; |
|
388 |
if (ref $_[0] eq 'HASH') { $end_filter = $_[0] } |
|
389 |
else { |
|
390 |
$end_filter = _array_to_hash( |
|
391 |
@_ > 1 ? [@_] : $_[0] |
|
392 |
); |
|
393 |
} |
|
394 |
for my $column (keys %$end_filter) { |
|
395 |
my $fname = $end_filter->{$column}; |
|
396 |
if (exists $end_filter->{$column} |
|
397 |
&& defined $fname |
|
398 |
&& ref $fname ne 'CODE') |
|
399 |
{ |
|
400 |
croak qq{Filter "$fname" is not registered" } . _subname |
|
401 |
unless exists $self->dbi->filters->{$fname}; |
|
402 |
$end_filter->{$column} = $self->dbi->filters->{$fname}; |
|
403 |
} |
|
cleanup
|
404 |
} |
cleanup
|
405 |
$self->{end_filter} = {%{$self->end_filter}, %$end_filter}; |
406 |
return $self; |
|
407 |
} |
|
408 |
return $self->{end_filter} ||= {}; |
|
cleanup
|
409 |
} |
cleanup
|
410 |
# DEPRECATED! |
added experimental DBIx::Cus...
|
411 |
sub remove_end_filter { |
cleanup
|
412 |
warn "remove_end_filter is DEPRECATED!"; |
413 |
my $self = shift; |
|
414 |
$self->{end_filter} = {}; |
|
415 |
return $self; |
|
added experimental DBIx::Cus...
|
416 |
} |
cleanup
|
417 |
# DEPRECATED! |
added experimental DBIx::Cus...
|
418 |
sub remove_filter { |
cleanup
|
419 |
warn "remove_filter is DEPRECATED!"; |
420 |
my $self = shift; |
|
421 |
$self->{filter} = {}; |
|
422 |
return $self; |
|
added experimental DBIx::Cus...
|
423 |
} |
cleanup
|
424 |
# DEPRECATED! |
cleanup
|
425 |
sub default_filter { |
cleanup
|
426 |
warn "default_filter is DEPRECATED!"; |
427 |
my $self = shift; |
|
428 |
if (@_) { |
|
429 |
my $fname = $_[0]; |
|
430 |
if (@_ && !$fname) { |
|
431 |
$self->{default_filter} = undef; |
|
cleanup
|
432 |
} |
cleanup
|
433 |
else { |
434 |
croak qq{Filter "$fname" is not registered} |
|
435 |
unless exists $self->dbi->filters->{$fname}; |
|
436 |
$self->{default_filter} = $self->dbi->filters->{$fname}; |
|
437 |
} |
|
438 |
return $self; |
|
439 |
} |
|
440 |
return $self->{default_filter}; |
|
cleanup
|
441 |
} |
cleanup
|
442 |
# DEPRECATED! |
cleanup
|
443 |
has 'filter_check'; |
cleanup
|
444 | |
update document
|
445 |
1; |
446 | ||
packaging one directory
|
447 |
=head1 NAME |
448 | ||
cleanup
|
449 |
DBIx::Custom::Result - Result of select statement |
packaging one directory
|
450 | |
update document
|
451 |
=head1 SYNOPSIS |
cleanup
|
452 | |
cleanup
|
453 |
# Result |
454 |
my $result = $dbi->select(table => 'book'); |
|
455 | ||
456 |
# Fetch a row and put it into array reference |
|
457 |
while (my $row = $result->fetch) { |
|
458 |
my $author = $row->[0]; |
|
459 |
my $title = $row->[1]; |
|
460 |
} |
|
461 |
|
|
462 |
# Fetch only a first row and put it into array reference |
|
463 |
my $row = $result->fetch_one; |
|
464 |
|
|
465 |
# Fetch all rows and put them into array of array reference |
|
466 |
my $rows = $result->fetch_all; |
|
467 | ||
468 |
# Fetch a row and put it into hash reference |
|
469 |
while (my $row = $result->fetch_hash) { |
|
470 |
my $title = $row->{title}; |
|
471 |
my $author = $row->{author}; |
|
472 |
} |
|
473 |
|
|
474 |
# Fetch only a first row and put it into hash reference |
|
475 |
my $row = $result->fetch_hash_one; |
|
476 |
my $row = $result->one; # Alias for "fetch_hash_one" |
|
477 |
|
|
478 |
# Fetch all rows and put them into array of hash reference |
|
479 |
my $rows = $result->fetch_hash_all; |
|
480 |
my $rows = $result->all; # Alias for "fetch_hash_all" |
|
packaging one directory
|
481 | |
update document
|
482 |
=head1 ATTRIBUTES |
packaging one directory
|
483 | |
sub module use DBIx::Custom ...
|
484 |
=head2 C<dbi> |
cleanup
|
485 | |
cleanup
|
486 |
my $dbi = $result->dbi; |
487 |
$result = $result->dbi($dbi); |
|
cleanup
|
488 | |
sub module use DBIx::Custom ...
|
489 |
L<DBIx::Custom> object. |
cleanup
|
490 | |
491 |
=head2 C<sth> |
|
492 | ||
cleanup
|
493 |
my $sth = $reuslt->sth |
494 |
$result = $result->sth($sth); |
|
cleanup
|
495 | |
496 |
Statement handle of L<DBI>. |
|
497 | ||
update document
|
498 |
=head1 METHODS |
499 | ||
renamed build_query to creat...
|
500 |
L<DBIx::Custom::Result> inherits all methods from L<Object::Simple> |
cleanup
|
501 |
and implements the following new ones. |
packaging one directory
|
502 | |
updated pod
|
503 |
=head2 C<all> |
504 | ||
cleanup
|
505 |
my $rows = $result->all; |
updated pod
|
506 | |
cleanup
|
507 |
Same as C<fetch_hash_all>. |
updated pod
|
508 | |
- removed EXPERIMENTAL statu...
|
509 |
=head2 C<column> |
- added EXPERIMENTAL DBIx::C...
|
510 | |
cleanup
|
511 |
my $column = $result->column; |
- added EXPERIMENTAL DBIx::C...
|
512 | |
513 |
Get first column's all values. |
|
514 | ||
cleanup
|
515 |
my $names = $dbi->select('name', table => 'book')->column; |
- added EXPERIMENTAL DBIx::C...
|
516 | |
removed DBIx::Custom commit ...
|
517 |
=head2 C<fetch> |
packaging one directory
|
518 | |
cleanup
|
519 |
my $row = $result->fetch; |
version 0.0901
|
520 | |
cleanup
|
521 |
Fetch a row and put it into array reference. |
packaging one directory
|
522 | |
removed DBIx::Custom commit ...
|
523 |
=head2 C<fetch_all> |
packaging one directory
|
524 | |
cleanup
|
525 |
my $rows = $result->fetch_all; |
version 0.0901
|
526 | |
cleanup
|
527 |
Fetch all rows and put them into array of array reference. |
packaging one directory
|
528 | |
- renamed DBIx::Custom::Resu...
|
529 |
=head2 C<fetch_one> |
cleanup
|
530 | |
cleanup
|
531 |
my $row = $result->fetch_one; |
cleanup
|
532 | |
cleanup
|
533 |
Fetch only a first row and put it into array reference, |
534 |
and finish statment handle. |
|
cleanup
|
535 | |
removed DESTROY method(not b...
|
536 |
=head2 C<fetch_hash> |
packaging one directory
|
537 | |
cleanup
|
538 |
my $row = $result->fetch_hash; |
packaging one directory
|
539 | |
cleanup
|
540 |
Fetch a row and put it into hash reference. |
update document
|
541 | |
cleanup
|
542 |
=head2 C<fetch_hash_all> |
543 | ||
cleanup
|
544 |
my $rows = $result->fetch_hash_all; |
cleanup
|
545 | |
cleanup
|
546 |
Fetch all rows and put them into array of hash reference. |
cleanup
|
547 | |
- renamed DBIx::Custom::Resu...
|
548 |
=head2 C<fetch_hash_one> |
cleanup
|
549 |
|
550 |
my $row = $result->fetch_hash_one; |
|
packaging one directory
|
551 | |
cleanup
|
552 |
Fetch only a first row and put it into hash reference, |
553 |
and finish statment handle. |
|
packaging one directory
|
554 | |
removed DESTROY method(not b...
|
555 |
=head2 C<fetch_hash_multi> |
update document
|
556 | |
cleanup
|
557 |
my $rows = $result->fetch_hash_multi(5); |
558 |
|
|
cleanup
|
559 |
Fetch multiple rows and put them into array of hash reference. |
update document
|
560 | |
cleanup
|
561 |
=head2 C<fetch_multi> |
packaging one directory
|
562 | |
cleanup
|
563 |
my $rows = $result->fetch_multi(5); |
564 |
|
|
cleanup
|
565 |
Fetch multiple rows and put them into array of array reference. |
removed DESTROY method(not b...
|
566 | |
cleanup
|
567 |
=head2 C<filter> |
568 | ||
cleanup
|
569 |
$result->filter(title => sub { uc $_[0] }, author => 'to_upper'); |
570 |
$result->filter([qw/title author/] => 'to_upper'); |
|
added experimental DBIx::Cus...
|
571 | |
cleanup
|
572 |
Set filter for column. |
573 |
You can use subroutine or filter name as filter. |
|
- DBIx::Custom Model filter ...
|
574 |
This filter is executed after C<type_rule> filter. |
cleanup
|
575 | |
added EXPERIMENTAL DBIx::Cus...
|
576 |
=head2 C<flat> EXPERIMENTAL |
577 | ||
578 |
my $flat = $result->flat; |
|
579 | ||
580 |
All value is flatten and added to one array reference. |
|
581 |
|
|
582 |
my @flat = $dbi->select(['id', 'title'])->flat; |
|
583 | ||
584 |
If C<fetch_all> method return the following data |
|
585 | ||
586 |
[ |
|
587 |
[1, 'Perl'], |
|
588 |
[2, 'Ruby'] |
|
589 |
] |
|
590 | ||
591 |
C<flat> method return the following data. |
|
592 | ||
593 |
(1, 'Perl', 2, 'Ruby') |
|
594 | ||
595 |
You can create key-value pair easily. |
|
596 | ||
597 |
my %titles = $dbi->select(['id', 'title'])->flat; |
|
598 | ||
- removed EXPERIMENTAL statu...
|
599 |
=head2 C<header> |
added EXPERIMENTAL DBIx::Cus...
|
600 | |
cleanup
|
601 |
my $header = $result->header; |
added EXPERIMENTAL DBIx::Cus...
|
602 | |
603 |
Get header column names. |
|
604 | ||
updated pod
|
605 |
=head2 C<one> |
606 | ||
cleanup
|
607 |
my $row = $result->one; |
updated pod
|
608 | |
- renamed DBIx::Custom::Resu...
|
609 |
Alias for C<fetch_hash_one>. |
added experimental DBIx::Cus...
|
610 | |
- removed DEPRECATED DBIx::C...
|
611 |
=head2 C<stash> |
added experimental DBIx::Cus...
|
612 | |
cleanup
|
613 |
my $stash = $result->stash; |
614 |
my $foo = $result->stash->{foo}; |
|
615 |
$result->stash->{foo} = $foo; |
|
added experimental DBIx::Cus...
|
616 | |
- added EXPERIMENTAL DBIx::C...
|
617 |
Stash is hash reference to save some data. |
added experimental DBIx::Cus...
|
618 | |
- removed EXPERIMENTAL flag ...
|
619 |
=head2 C<type_rule> |
cleanup
|
620 |
|
621 |
# Merge type rule |
|
622 |
$result->type_rule( |
|
623 |
# DATE |
|
624 |
9 => sub { ... }, |
|
625 |
# DATETIME or TIMESTAMP |
|
626 |
11 => sub { ... } |
|
627 |
); |
|
628 | ||
629 |
# Replace type rule(by reference) |
|
630 |
$result->type_rule([ |
|
631 |
# DATE |
|
632 |
9 => sub { ... }, |
|
633 |
# DATETIME or TIMESTAMP |
|
634 |
11 => sub { ... } |
|
635 |
]); |
|
EXPERIMENTAL type_rule_off i...
|
636 | |
cleanup
|
637 |
This is same as L<DBIx::Custom>'s C<type_rule>'s <from>. |
EXPERIMENTAL type_rule_off i...
|
638 | |
- removed EXPERIMENTAL flag ...
|
639 |
=head2 C<type_rule_off> |
- changed EXPERIMENTAL DBIx:...
|
640 | |
cleanup
|
641 |
$result = $result->type_rule_off; |
- changed EXPERIMENTAL DBIx:...
|
642 | |
643 |
Turn C<from1> and C<from2> type rule off. |
|
644 |
By default, type rule is on. |
|
645 | ||
- removed EXPERIMENTAL flag ...
|
646 |
=head2 C<type_rule_on> |
- changed EXPERIMENTAL DBIx:...
|
647 | |
cleanup
|
648 |
$result = $result->type_rule_on; |
- changed EXPERIMENTAL DBIx:...
|
649 | |
650 |
Turn C<from1> and C<from2> type rule on. |
|
651 |
By default, type rule is on. |
|
652 | ||
- removed EXPERIMENTAL flag ...
|
653 |
=head2 C<type_rule1_off> |
- changed EXPERIMENTAL DBIx:...
|
654 | |
cleanup
|
655 |
$result = $result->type_rule1_off; |
- changed EXPERIMENTAL DBIx:...
|
656 | |
657 |
Turn C<from1> type rule off. |
|
658 |
By default, type rule is on. |
|
659 | ||
- removed EXPERIMENTAL flag ...
|
660 |
=head2 C<type_rule1_on> |
- changed EXPERIMENTAL DBIx:...
|
661 | |
cleanup
|
662 |
$result = $result->type_rule1_on; |
- changed EXPERIMENTAL DBIx:...
|
663 | |
664 |
Turn C<from1> type rule on. |
|
665 |
By default, type rule is on. |
|
666 | ||
- removed EXPERIMENTAL flag ...
|
667 |
=head2 C<type_rule2_off> |
- changed EXPERIMENTAL DBIx:...
|
668 | |
cleanup
|
669 |
$result = $result->type_rule2_off; |
- changed EXPERIMENTAL DBIx:...
|
670 | |
671 |
Turn C<from2> type rule off. |
|
672 |
By default, type rule is on. |
|
673 | ||
- removed EXPERIMENTAL flag ...
|
674 |
=head2 C<type_rule2_on> |
- changed EXPERIMENTAL DBIx:...
|
675 | |
cleanup
|
676 |
$result = $result->type_rule2_on; |
- changed EXPERIMENTAL DBIx:...
|
677 | |
678 |
Turn C<from2> type rule on. |
|
679 |
By default, type rule is on. |
|
680 | ||
- removed EXPERIMENTAL statu...
|
681 |
=head2 C<value> |
- added EXPERIMENTAL DBIx::C...
|
682 | |
cleanup
|
683 |
my $value = $result->value; |
- added EXPERIMENTAL DBIx::C...
|
684 | |
685 |
Get first column's first value. |
|
686 | ||
cleanup
|
687 |
my $count = $dbi->select('count(*)')->value; |
- added EXPERIMENTAL DBIx::C...
|
688 | |
packaging one directory
|
689 |
=cut |