- added EXPERIMENTAL DBIx::Custom::Result::value...
...method
... | ... |
@@ -1,3 +1,6 @@ |
1 |
+0.2105 |
|
2 |
+ - added EXPERIMENTAL DBIx::Custom::Result::value method |
|
3 |
+ - added EXPERIMENTAL DBIx::Custom::Result::column method |
|
1 | 4 |
0.2104 |
2 | 5 |
- improved bulk_insert performance |
3 | 6 |
0.2103 |
... | ... |
@@ -1,7 +1,7 @@ |
1 | 1 |
package DBIx::Custom; |
2 | 2 |
use Object::Simple -base; |
3 | 3 |
|
4 |
-our $VERSION = '0.2104'; |
|
4 |
+our $VERSION = '0.2105'; |
|
5 | 5 |
use 5.008001; |
6 | 6 |
|
7 | 7 |
use Carp 'croak'; |
... | ... |
@@ -1,13 +0,0 @@ |
1 |
-=encoding utf8 |
|
2 |
- |
|
3 |
-=head1 NAME |
|
4 |
- |
|
5 |
-DBIx::Custom::Guide - DBIx::Customガイド |
|
6 |
- |
|
7 |
-=head1 LINK |
|
8 |
- |
|
9 |
-ドキュメントは以下のリンクに移動しました。 |
|
10 |
- |
|
11 |
-L<http://d.hatena.ne.jp/perlcodesample/20110401/1305597081> |
|
12 |
- |
|
13 |
-=cut |
... | ... |
@@ -9,6 +9,15 @@ has [qw/dbi sth/], |
9 | 9 |
|
10 | 10 |
*all = \&fetch_hash_all; |
11 | 11 |
|
12 |
+sub column { |
|
13 |
+ my $self = shift; |
|
14 |
+ |
|
15 |
+ my $column = []; |
|
16 |
+ my $rows = $self->fetch_all; |
|
17 |
+ push @$column, $_->[0] for @$rows; |
|
18 |
+ return $column; |
|
19 |
+} |
|
20 |
+ |
|
12 | 21 |
sub filter { |
13 | 22 |
my $self = shift; |
14 | 23 |
|
... | ... |
@@ -305,6 +314,13 @@ sub type_rule2_on { |
305 | 314 |
return $self; |
306 | 315 |
} |
307 | 316 |
|
317 |
+sub value { |
|
318 |
+ my $self = shift; |
|
319 |
+ my $row = $self->fetch_first; |
|
320 |
+ my $value = $row ? $row->[0] : undef; |
|
321 |
+ return $value; |
|
322 |
+} |
|
323 |
+ |
|
308 | 324 |
sub _cache { |
309 | 325 |
my $self = shift; |
310 | 326 |
$self->{_type_map} = {}; |
... | ... |
@@ -465,6 +481,14 @@ and implements the following new ones. |
465 | 481 |
|
466 | 482 |
Same as C<fetch_hash_all>. |
467 | 483 |
|
484 |
+=head2 C<column> EXPERIMENTAL |
|
485 |
+ |
|
486 |
+ my $column = $result->column; |
|
487 |
+ |
|
488 |
+Get first column's all values. |
|
489 |
+ |
|
490 |
+ my $names = $dbi->select('name', table => 'book')->column; |
|
491 |
+ |
|
468 | 492 |
=head2 C<fetch> |
469 | 493 |
|
470 | 494 |
my $row = $result->fetch; |
... | ... |
@@ -542,7 +566,7 @@ Same as C<fetch_hash_first>. |
542 | 566 |
my $foo = $result->stash->{foo}; |
543 | 567 |
$result->stash->{foo} = $foo; |
544 | 568 |
|
545 |
-Stash is hash reference for data. |
|
569 |
+Stash is hash reference to save some data. |
|
546 | 570 |
|
547 | 571 |
=head2 C<type_rule> |
548 | 572 |
|
... | ... |
@@ -606,4 +630,12 @@ By default, type rule is on. |
606 | 630 |
Turn C<from2> type rule on. |
607 | 631 |
By default, type rule is on. |
608 | 632 |
|
633 |
+=head2 C<value> EXPERIMENTAL |
|
634 |
+ |
|
635 |
+ my $value = $result->value; |
|
636 |
+ |
|
637 |
+Get first column's first value. |
|
638 |
+ |
|
639 |
+ my $count = $dbi->select('count(*)')->value; |
|
640 |
+ |
|
609 | 641 |
=cut |
... | ... |
@@ -298,12 +298,17 @@ is_deeply(\@rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "fetch_h |
298 | 298 |
|
299 | 299 |
$result = $dbi->execute($query); |
300 | 300 |
$rows = $result->fetch_all; |
301 |
-is_deeply($rows, [[1, 2], [3, 4]], "fetch_all"); |
|
301 |
+is_deeply($rows, [[1, 2], [3, 4]]); |
|
302 | 302 |
|
303 | 303 |
$result = $dbi->execute($query); |
304 | 304 |
$rows = $result->fetch_hash_all; |
305 | 305 |
is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "all"); |
306 | 306 |
|
307 |
+is_deeply($dbi->select($key1, table => $table1)->column, [1, 3]); |
|
308 |
+ |
|
309 |
+is($dbi->select('count(*)', table => $table1)->value, 2); |
|
310 |
+ok(!defined $dbi->select($key1, table => $table1, where => {$key1 => 10})->value); |
|
311 |
+ |
|
307 | 312 |
test 'Insert query return value'; |
308 | 313 |
$source = "insert into $table1 {insert_param $key1 $key2}"; |
309 | 314 |
$query = $dbi->execute($source, {}, query => 1); |