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 EXPERIMETAL DBIx::Cust...
|
259 |
sub kv { |
260 |
my ($self, %opt) = @_; |
|
261 | ||
262 |
my $key_name = $self->{sth}{NAME}[0]; |
|
263 |
my $kv = {}; |
|
264 |
while (my $row = $self->fetch_hash) { |
|
265 |
my $key_value = delete $row->{$key_name}; |
|
266 |
next unless defined $key_value; |
|
267 |
if ($opt{multi}) { |
|
268 |
$kv->{$key_value} ||= []; |
|
269 |
push @{$kv->{$key_value}}, $row; |
|
270 |
} |
|
271 |
else { $kv->{$key_value} = $row } |
|
272 |
} |
|
273 |
|
|
274 |
return $kv; |
|
275 |
} |
|
276 | ||
added EXPERIMENTAL DBIx::Cus...
|
277 |
sub header { shift->sth->{NAME} } |
278 | ||
- renamed DBIx::Custom::Resu...
|
279 |
*one = \&fetch_hash_one; |
- added DBIx::Custom::Result...
|
280 | |
added EXPERIMENTAL DBIx::Cus...
|
281 |
sub type_rule { |
cleanup
|
282 |
my $self = shift; |
283 |
|
|
284 |
if (@_) { |
|
285 |
my $type_rule = ref $_[0] eq 'HASH' ? $_[0] : {@_}; |
|
286 | ||
287 |
# From |
|
288 |
for my $i (1 .. 2) { |
|
289 |
$type_rule->{"from$i"} = _array_to_hash($type_rule->{"from$i"}); |
|
290 |
for my $data_type (keys %{$type_rule->{"from$i"} || {}}) { |
|
291 |
croak qq{data type of from$i section must be lower case or number} |
|
292 |
if $data_type =~ /[A-Z]/; |
|
293 |
my $fname = $type_rule->{"from$i"}{$data_type}; |
|
294 |
if (defined $fname && ref $fname ne 'CODE') { |
|
295 |
croak qq{Filter "$fname" is not registered" } . _subname |
|
296 |
unless exists $self->dbi->filters->{$fname}; |
|
297 |
|
|
298 |
$type_rule->{"from$i"}{$data_type} = $self->dbi->filters->{$fname}; |
|
added EXPERIMENTAL DBIx::Cus...
|
299 |
} |
cleanup
|
300 |
} |
added EXPERIMENTAL DBIx::Cus...
|
301 |
} |
cleanup
|
302 |
$self->{type_rule} = $type_rule; |
added EXPERIMENTAL DBIx::Cus...
|
303 |
|
cleanup
|
304 |
return $self; |
305 |
} |
|
306 |
|
|
307 |
return $self->{type_rule} || {}; |
|
added EXPERIMENTAL DBIx::Cus...
|
308 |
} |
309 | ||
- changed EXPERIMENTAL DBIx:...
|
310 |
sub type_rule_off { |
cleanup
|
311 |
my $self = shift; |
312 |
$self->{type_rule_off} = 1; |
|
313 |
return $self; |
|
- changed EXPERIMENTAL DBIx:...
|
314 |
} |
315 | ||
316 |
sub type_rule_on { |
|
cleanup
|
317 |
my $self = shift; |
318 |
$self->{type_rule_off} = 0; |
|
319 |
return $self; |
|
- changed EXPERIMENTAL DBIx:...
|
320 |
} |
321 | ||
322 |
sub type_rule1_off { |
|
cleanup
|
323 |
my $self = shift; |
324 |
$self->{type_rule1_off} = 1; |
|
325 |
return $self; |
|
- changed EXPERIMENTAL DBIx:...
|
326 |
} |
327 | ||
328 |
sub type_rule1_on { |
|
cleanup
|
329 |
my $self = shift; |
330 |
$self->{type_rule1_off} = 0; |
|
331 |
return $self; |
|
- changed EXPERIMENTAL DBIx:...
|
332 |
} |
333 | ||
334 |
sub type_rule2_off { |
|
cleanup
|
335 |
my $self = shift; |
336 |
$self->{type_rule2_off} = 1; |
|
337 |
return $self; |
|
- changed EXPERIMENTAL DBIx:...
|
338 |
} |
339 | ||
340 |
sub type_rule2_on { |
|
cleanup
|
341 |
my $self = shift; |
342 |
$self->{type_rule2_off} = 0; |
|
343 |
return $self; |
|
- changed EXPERIMENTAL DBIx:...
|
344 |
} |
345 | ||
- added EXPERIMENTAL DBIx::C...
|
346 |
sub value { |
cleanup
|
347 |
my $self = shift; |
348 |
my $row = $self->fetch_one; |
|
349 |
my $value = $row ? $row->[0] : undef; |
|
350 |
return $value; |
|
- added EXPERIMENTAL DBIx::C...
|
351 |
} |
352 | ||
- fixed bug DBIx::Custom::Re...
|
353 |
sub _cache { |
cleanup
|
354 |
my $self = shift; |
355 |
$self->{_type_map} = {}; |
|
356 |
$self->{_pos} = {}; |
|
357 |
$self->{_columns} = {}; |
|
- removed EXPERIMENTAL statu...
|
358 |
for (my $i = 0; $i < @{$self->{sth}->{NAME} || []}; $i++) { |
cleanup
|
359 |
my $type = lc $self->{sth}{TYPE}[$i]; |
360 |
my $name = $self->{sth}{NAME}[$i]; |
|
361 |
$self->{_type_map}{$type} ||= []; |
|
362 |
push @{$self->{_type_map}{$type}}, $name; |
|
363 |
$self->{_pos}{$name} ||= []; |
|
364 |
push @{$self->{_pos}{$name}}, $i; |
|
365 |
$self->{_columns}{$name} = 1; |
|
366 |
} |
|
367 |
$self->{_cache} = 1; |
|
- fixed bug DBIx::Custom::Re...
|
368 |
} |
369 | ||
- renamed DBIx::Custom::Resu...
|
370 |
# DEPRECATED! |
371 |
sub fetch_hash_first { |
|
cleanup
|
372 |
my $self = shift; |
373 |
warn "DBIx::Custom::Result::fetch_hash_first is DEPRECATED! use fetch_hash_one instead"; |
|
374 |
return $self->fetch_hash_one(@_); |
|
- renamed DBIx::Custom::Resu...
|
375 |
} |
376 | ||
377 |
# DEPRECATED! |
|
378 |
sub fetch_first { |
|
cleanup
|
379 |
my $self = shift; |
380 |
warn "DBIx::Custom::Result::fetch_first is DEPRECATED! use fetch_one instead"; |
|
381 |
return $self->fetch_one(@_); |
|
- renamed DBIx::Custom::Resu...
|
382 |
} |
383 | ||
- DBIx::Custom::Result filte...
|
384 |
# DEPRECATED! |
385 |
sub filter_off { |
|
cleanup
|
386 |
warn "filter_off method is DEPRECATED!"; |
387 |
my $self = shift; |
|
388 |
$self->{filter_off} = 1; |
|
389 |
return $self; |
|
- DBIx::Custom::Result filte...
|
390 |
} |
391 | ||
392 |
# DEPRECATED! |
|
393 |
sub filter_on { |
|
cleanup
|
394 |
warn "filter_on method is DEPRECATED!"; |
395 |
my $self = shift; |
|
396 |
$self->{filter_off} = 0; |
|
397 |
return $self; |
|
- DBIx::Custom::Result filte...
|
398 |
} |
399 | ||
cleanup
|
400 |
# DEPRECATED! |
401 |
sub end_filter { |
|
cleanup
|
402 |
warn "end_filter method is DEPRECATED!"; |
403 |
my $self = shift; |
|
404 |
if (@_) { |
|
405 |
my $end_filter = {}; |
|
406 |
if (ref $_[0] eq 'HASH') { $end_filter = $_[0] } |
|
407 |
else { |
|
408 |
$end_filter = _array_to_hash( |
|
409 |
@_ > 1 ? [@_] : $_[0] |
|
410 |
); |
|
411 |
} |
|
412 |
for my $column (keys %$end_filter) { |
|
413 |
my $fname = $end_filter->{$column}; |
|
414 |
if (exists $end_filter->{$column} |
|
415 |
&& defined $fname |
|
416 |
&& ref $fname ne 'CODE') |
|
417 |
{ |
|
418 |
croak qq{Filter "$fname" is not registered" } . _subname |
|
419 |
unless exists $self->dbi->filters->{$fname}; |
|
420 |
$end_filter->{$column} = $self->dbi->filters->{$fname}; |
|
421 |
} |
|
cleanup
|
422 |
} |
cleanup
|
423 |
$self->{end_filter} = {%{$self->end_filter}, %$end_filter}; |
424 |
return $self; |
|
425 |
} |
|
426 |
return $self->{end_filter} ||= {}; |
|
cleanup
|
427 |
} |
cleanup
|
428 |
# DEPRECATED! |
added experimental DBIx::Cus...
|
429 |
sub remove_end_filter { |
cleanup
|
430 |
warn "remove_end_filter is DEPRECATED!"; |
431 |
my $self = shift; |
|
432 |
$self->{end_filter} = {}; |
|
433 |
return $self; |
|
added experimental DBIx::Cus...
|
434 |
} |
cleanup
|
435 |
# DEPRECATED! |
added experimental DBIx::Cus...
|
436 |
sub remove_filter { |
cleanup
|
437 |
warn "remove_filter is DEPRECATED!"; |
438 |
my $self = shift; |
|
439 |
$self->{filter} = {}; |
|
440 |
return $self; |
|
added experimental DBIx::Cus...
|
441 |
} |
cleanup
|
442 |
# DEPRECATED! |
cleanup
|
443 |
sub default_filter { |
cleanup
|
444 |
warn "default_filter is DEPRECATED!"; |
445 |
my $self = shift; |
|
446 |
if (@_) { |
|
447 |
my $fname = $_[0]; |
|
448 |
if (@_ && !$fname) { |
|
449 |
$self->{default_filter} = undef; |
|
cleanup
|
450 |
} |
cleanup
|
451 |
else { |
452 |
croak qq{Filter "$fname" is not registered} |
|
453 |
unless exists $self->dbi->filters->{$fname}; |
|
454 |
$self->{default_filter} = $self->dbi->filters->{$fname}; |
|
455 |
} |
|
456 |
return $self; |
|
457 |
} |
|
458 |
return $self->{default_filter}; |
|
cleanup
|
459 |
} |
cleanup
|
460 |
# DEPRECATED! |
cleanup
|
461 |
has 'filter_check'; |
cleanup
|
462 | |
update document
|
463 |
1; |
464 | ||
packaging one directory
|
465 |
=head1 NAME |
466 | ||
cleanup
|
467 |
DBIx::Custom::Result - Result of select statement |
packaging one directory
|
468 | |
update document
|
469 |
=head1 SYNOPSIS |
cleanup
|
470 | |
cleanup
|
471 |
# Result |
472 |
my $result = $dbi->select(table => 'book'); |
|
473 | ||
474 |
# Fetch a row and put it into array reference |
|
475 |
while (my $row = $result->fetch) { |
|
476 |
my $author = $row->[0]; |
|
477 |
my $title = $row->[1]; |
|
478 |
} |
|
479 |
|
|
480 |
# Fetch only a first row and put it into array reference |
|
481 |
my $row = $result->fetch_one; |
|
482 |
|
|
483 |
# Fetch all rows and put them into array of array reference |
|
484 |
my $rows = $result->fetch_all; |
|
485 | ||
486 |
# Fetch a row and put it into hash reference |
|
487 |
while (my $row = $result->fetch_hash) { |
|
488 |
my $title = $row->{title}; |
|
489 |
my $author = $row->{author}; |
|
490 |
} |
|
491 |
|
|
492 |
# Fetch only a first row and put it into hash reference |
|
493 |
my $row = $result->fetch_hash_one; |
|
494 |
my $row = $result->one; # Alias for "fetch_hash_one" |
|
495 |
|
|
496 |
# Fetch all rows and put them into array of hash reference |
|
497 |
my $rows = $result->fetch_hash_all; |
|
498 |
my $rows = $result->all; # Alias for "fetch_hash_all" |
|
packaging one directory
|
499 | |
update document
|
500 |
=head1 ATTRIBUTES |
packaging one directory
|
501 | |
sub module use DBIx::Custom ...
|
502 |
=head2 C<dbi> |
cleanup
|
503 | |
cleanup
|
504 |
my $dbi = $result->dbi; |
505 |
$result = $result->dbi($dbi); |
|
cleanup
|
506 | |
sub module use DBIx::Custom ...
|
507 |
L<DBIx::Custom> object. |
cleanup
|
508 | |
509 |
=head2 C<sth> |
|
510 | ||
cleanup
|
511 |
my $sth = $reuslt->sth |
512 |
$result = $result->sth($sth); |
|
cleanup
|
513 | |
514 |
Statement handle of L<DBI>. |
|
515 | ||
update document
|
516 |
=head1 METHODS |
517 | ||
renamed build_query to creat...
|
518 |
L<DBIx::Custom::Result> inherits all methods from L<Object::Simple> |
cleanup
|
519 |
and implements the following new ones. |
packaging one directory
|
520 | |
updated pod
|
521 |
=head2 C<all> |
522 | ||
cleanup
|
523 |
my $rows = $result->all; |
updated pod
|
524 | |
cleanup
|
525 |
Same as C<fetch_hash_all>. |
updated pod
|
526 | |
- removed EXPERIMENTAL statu...
|
527 |
=head2 C<column> |
- added EXPERIMENTAL DBIx::C...
|
528 | |
cleanup
|
529 |
my $column = $result->column; |
- added EXPERIMENTAL DBIx::C...
|
530 | |
531 |
Get first column's all values. |
|
532 | ||
cleanup
|
533 |
my $names = $dbi->select('name', table => 'book')->column; |
- added EXPERIMENTAL DBIx::C...
|
534 | |
removed DBIx::Custom commit ...
|
535 |
=head2 C<fetch> |
packaging one directory
|
536 | |
cleanup
|
537 |
my $row = $result->fetch; |
version 0.0901
|
538 | |
cleanup
|
539 |
Fetch a row and put it into array reference. |
packaging one directory
|
540 | |
removed DBIx::Custom commit ...
|
541 |
=head2 C<fetch_all> |
packaging one directory
|
542 | |
cleanup
|
543 |
my $rows = $result->fetch_all; |
version 0.0901
|
544 | |
cleanup
|
545 |
Fetch all rows and put them into array of array reference. |
packaging one directory
|
546 | |
- renamed DBIx::Custom::Resu...
|
547 |
=head2 C<fetch_one> |
cleanup
|
548 | |
cleanup
|
549 |
my $row = $result->fetch_one; |
cleanup
|
550 | |
cleanup
|
551 |
Fetch only a first row and put it into array reference, |
552 |
and finish statment handle. |
|
cleanup
|
553 | |
removed DESTROY method(not b...
|
554 |
=head2 C<fetch_hash> |
packaging one directory
|
555 | |
cleanup
|
556 |
my $row = $result->fetch_hash; |
packaging one directory
|
557 | |
cleanup
|
558 |
Fetch a row and put it into hash reference. |
update document
|
559 | |
cleanup
|
560 |
=head2 C<fetch_hash_all> |
561 | ||
cleanup
|
562 |
my $rows = $result->fetch_hash_all; |
cleanup
|
563 | |
cleanup
|
564 |
Fetch all rows and put them into array of hash reference. |
cleanup
|
565 | |
- renamed DBIx::Custom::Resu...
|
566 |
=head2 C<fetch_hash_one> |
cleanup
|
567 |
|
568 |
my $row = $result->fetch_hash_one; |
|
packaging one directory
|
569 | |
cleanup
|
570 |
Fetch only a first row and put it into hash reference, |
571 |
and finish statment handle. |
|
packaging one directory
|
572 | |
removed DESTROY method(not b...
|
573 |
=head2 C<fetch_hash_multi> |
update document
|
574 | |
cleanup
|
575 |
my $rows = $result->fetch_hash_multi(5); |
576 |
|
|
cleanup
|
577 |
Fetch multiple rows and put them into array of hash reference. |
update document
|
578 | |
cleanup
|
579 |
=head2 C<fetch_multi> |
packaging one directory
|
580 | |
cleanup
|
581 |
my $rows = $result->fetch_multi(5); |
582 |
|
|
cleanup
|
583 |
Fetch multiple rows and put them into array of array reference. |
removed DESTROY method(not b...
|
584 | |
cleanup
|
585 |
=head2 C<filter> |
586 | ||
cleanup
|
587 |
$result->filter(title => sub { uc $_[0] }, author => 'to_upper'); |
588 |
$result->filter([qw/title author/] => 'to_upper'); |
|
added experimental DBIx::Cus...
|
589 | |
cleanup
|
590 |
Set filter for column. |
591 |
You can use subroutine or filter name as filter. |
|
- DBIx::Custom Model filter ...
|
592 |
This filter is executed after C<type_rule> filter. |
cleanup
|
593 | |
- removed EXPERIMENTAL statu...
|
594 |
=head2 C<flat> |
added EXPERIMENTAL DBIx::Cus...
|
595 | |
596 |
my $flat = $result->flat; |
|
597 | ||
598 |
All value is flatten and added to one array reference. |
|
599 |
|
|
600 |
my @flat = $dbi->select(['id', 'title'])->flat; |
|
601 | ||
602 |
If C<fetch_all> method return the following data |
|
603 | ||
604 |
[ |
|
605 |
[1, 'Perl'], |
|
606 |
[2, 'Ruby'] |
|
607 |
] |
|
608 | ||
609 |
C<flat> method return the following data. |
|
610 | ||
611 |
(1, 'Perl', 2, 'Ruby') |
|
612 | ||
613 |
You can create key-value pair easily. |
|
614 | ||
615 |
my %titles = $dbi->select(['id', 'title'])->flat; |
|
616 | ||
- removed EXPERIMENTAL statu...
|
617 |
=head2 C<kv> |
added EXPERIMETAL DBIx::Cust...
|
618 | |
619 |
my $key_value = $result->kv; |
|
620 |
my $key_values = $result->kv(multi => 1); |
|
621 | ||
622 |
Get key-value pairs. |
|
623 | ||
624 |
my $books = $dbi->select(['id', 'title', 'author'])->kv; |
|
625 | ||
626 |
If C<all> method return the following data: |
|
627 | ||
628 |
[ |
|
629 |
{id => 1, title => 'Perl', author => 'Ken'}, |
|
630 |
{id => 2, title => 'Ruby', author => 'Taro'} |
|
631 |
] |
|
632 | ||
633 |
C<kv> method return the following data. |
|
634 | ||
635 |
{ |
|
636 |
1 => {title => 'Perl', author => 'Ken'}, |
|
637 |
2 => {title => 'Ruby', author => 'Taro'} |
|
638 |
} |
|
639 | ||
640 |
First column value become key. |
|
641 | ||
642 |
If value contains multipule data, you can push it to |
|
643 |
array refernce by C<multi> option. |
|
644 | ||
645 |
my $books = $dbi->select(['author', 'title', 'price'])->kv(multi => 1); |
|
646 | ||
647 |
If C<all> method return the following data: |
|
648 | ||
649 |
[ |
|
650 |
{author => 'Ken', title => 'Perl', price => 1000}, |
|
651 |
{author => 'Ken', title => 'Good', price => 2000}, |
|
652 |
{author => 'Taro', title => 'Ruby', price => 3000} |
|
653 |
{author => 'Taro', title => 'Sky', price => 4000} |
|
654 |
] |
|
655 | ||
656 |
C<kv> method return the following data. |
|
657 | ||
658 |
{ |
|
659 |
Ken => [ |
|
660 |
{title => 'Perl', price => 1000}, |
|
661 |
{title => 'Good', price => 2000} |
|
662 |
], |
|
663 |
Taro => [ |
|
664 |
{title => 'Ruby', price => 3000}, |
|
665 |
{title => 'Sky', price => 4000} |
|
666 |
] |
|
667 |
} |
|
668 | ||
- removed EXPERIMENTAL statu...
|
669 |
=head2 C<header> |
added EXPERIMENTAL DBIx::Cus...
|
670 | |
cleanup
|
671 |
my $header = $result->header; |
added EXPERIMENTAL DBIx::Cus...
|
672 | |
673 |
Get header column names. |
|
674 | ||
updated pod
|
675 |
=head2 C<one> |
676 | ||
cleanup
|
677 |
my $row = $result->one; |
updated pod
|
678 | |
- renamed DBIx::Custom::Resu...
|
679 |
Alias for C<fetch_hash_one>. |
added experimental DBIx::Cus...
|
680 | |
- removed DEPRECATED DBIx::C...
|
681 |
=head2 C<stash> |
added experimental DBIx::Cus...
|
682 | |
cleanup
|
683 |
my $stash = $result->stash; |
684 |
my $foo = $result->stash->{foo}; |
|
685 |
$result->stash->{foo} = $foo; |
|
added experimental DBIx::Cus...
|
686 | |
- added EXPERIMENTAL DBIx::C...
|
687 |
Stash is hash reference to save some data. |
added experimental DBIx::Cus...
|
688 | |
- removed EXPERIMENTAL flag ...
|
689 |
=head2 C<type_rule> |
cleanup
|
690 |
|
691 |
# Merge type rule |
|
692 |
$result->type_rule( |
|
693 |
# DATE |
|
694 |
9 => sub { ... }, |
|
695 |
# DATETIME or TIMESTAMP |
|
696 |
11 => sub { ... } |
|
697 |
); |
|
698 | ||
699 |
# Replace type rule(by reference) |
|
700 |
$result->type_rule([ |
|
701 |
# DATE |
|
702 |
9 => sub { ... }, |
|
703 |
# DATETIME or TIMESTAMP |
|
704 |
11 => sub { ... } |
|
705 |
]); |
|
EXPERIMENTAL type_rule_off i...
|
706 | |
cleanup
|
707 |
This is same as L<DBIx::Custom>'s C<type_rule>'s <from>. |
EXPERIMENTAL type_rule_off i...
|
708 | |
- removed EXPERIMENTAL flag ...
|
709 |
=head2 C<type_rule_off> |
- changed EXPERIMENTAL DBIx:...
|
710 | |
cleanup
|
711 |
$result = $result->type_rule_off; |
- changed EXPERIMENTAL DBIx:...
|
712 | |
713 |
Turn C<from1> and C<from2> type rule off. |
|
714 |
By default, type rule is on. |
|
715 | ||
- removed EXPERIMENTAL flag ...
|
716 |
=head2 C<type_rule_on> |
- changed EXPERIMENTAL DBIx:...
|
717 | |
cleanup
|
718 |
$result = $result->type_rule_on; |
- changed EXPERIMENTAL DBIx:...
|
719 | |
720 |
Turn C<from1> and C<from2> type rule on. |
|
721 |
By default, type rule is on. |
|
722 | ||
- removed EXPERIMENTAL flag ...
|
723 |
=head2 C<type_rule1_off> |
- changed EXPERIMENTAL DBIx:...
|
724 | |
cleanup
|
725 |
$result = $result->type_rule1_off; |
- changed EXPERIMENTAL DBIx:...
|
726 | |
727 |
Turn C<from1> type rule off. |
|
728 |
By default, type rule is on. |
|
729 | ||
- removed EXPERIMENTAL flag ...
|
730 |
=head2 C<type_rule1_on> |
- changed EXPERIMENTAL DBIx:...
|
731 | |
cleanup
|
732 |
$result = $result->type_rule1_on; |
- changed EXPERIMENTAL DBIx:...
|
733 | |
734 |
Turn C<from1> type rule on. |
|
735 |
By default, type rule is on. |
|
736 | ||
- removed EXPERIMENTAL flag ...
|
737 |
=head2 C<type_rule2_off> |
- changed EXPERIMENTAL DBIx:...
|
738 | |
cleanup
|
739 |
$result = $result->type_rule2_off; |
- changed EXPERIMENTAL DBIx:...
|
740 | |
741 |
Turn C<from2> type rule off. |
|
742 |
By default, type rule is on. |
|
743 | ||
- removed EXPERIMENTAL flag ...
|
744 |
=head2 C<type_rule2_on> |
- changed EXPERIMENTAL DBIx:...
|
745 | |
cleanup
|
746 |
$result = $result->type_rule2_on; |
- changed EXPERIMENTAL DBIx:...
|
747 | |
748 |
Turn C<from2> type rule on. |
|
749 |
By default, type rule is on. |
|
750 | ||
- removed EXPERIMENTAL statu...
|
751 |
=head2 C<value> |
- added EXPERIMENTAL DBIx::C...
|
752 | |
cleanup
|
753 |
my $value = $result->value; |
- added EXPERIMENTAL DBIx::C...
|
754 | |
755 |
Get first column's first value. |
|
756 | ||
cleanup
|
757 |
my $count = $dbi->select('count(*)')->value; |
- added EXPERIMENTAL DBIx::C...
|
758 | |
packaging one directory
|
759 |
=cut |