Acrux-DBI

 view release on metacpan or  search on metacpan

lib/Acrux/DBI/Res.pm  view on Meta::CPAN

=head2 dbi

    my $dbi = $res->dbi;
    $res = $res->dbi(Acrux::DBI->new);

L<Acrux::DBI> object these results belong to.

=head2 sth

    my $sth  = $res->sth;
    $res = $res->sth($sth);

L<Acrux::DBI> statement handle results are fetched from

=head1 METHODS

This class implements the following methods

=head2 affected_rows

    my $affected = $res->affected_rows;

Number of affected rows by the query. For example

    UPDATE testtable SET id = 1 WHERE id = 1

would return 1

=head2 array

    my $array = $res->array;

Fetch one row from L</"sth"> and return it as an array reference

    # [
    #   'foo', 'bar', 'baz'
    # ]

See also L<CTK::DBI/record>

=head2 arrays

    my $arrays = $res->arrays;

Fetch all rows from L</"sth"> and return them as an array of arrays

    # [
    #   [ 'foo', 'bar', 'baz' ],
    #   [ 'qux', 'quux' ],
    # ]

See also L<CTK::DBI/table>

=head2 collection

    my $collection = $res->collection;

Fetch all rows from L</"sth"> and return them as a L<Mojo::Collection> object containing hash references

    # Process all rows at once
    say $res->collection->reduce(sub { $a + $b->{money} }, 0);

=head2 collection_list

    my $collection_list = $res->collection_list;

Fetch all rows from L</"sth"> and return them as a L<Mojo::Collection> object containing array references

    # Process all rows at once
    say $res->collection_list->reduce(sub { $a + $b->[3] }, 0);

=head2 columns

    my $columns = $res->columns;

Return column names as an array reference

    # Names of all columns
    say for @{$res->columns};

=head2 err

    my $err = $res->err;

Error code received

=head2 errstr

    my $errstr = $res->errstr;

Error message received

=head2 finish

    $res->finish;

Indicate that you are finished with L</"sth"> and will not be fetching all the remaining rows

=head2 hash

    my $hash = $res->hash;

Fetch one row from L</"sth"> and return it as a hash reference

    # {
    #   'foo' => 1,
    #   'bar' => 'one',
    # }

See also L<CTK::DBI/recordh>

=head2 hashed_by

    my $hash = $res->hashed_by( $key_field );
    my $hash = $res->hashed_by( 'id' );

This method returns a reference to a hash containing a key for each distinct
value of the C<$key_field> column that was fetched.
For each key the corresponding value is a reference to a hash containing
all the selected columns and their values, as returned by C<fetchrow_hashref()>

For example:

    my $hash = $res->hashed_by( 'id' );

    # {
    #   1 => {
    #      'id'   => 1,
    #      'name' => 'foo'
    #   },
    #   2 => {
    #      'id'   => 2,
    #      'name' => 'bar'
    #   }
    # }

See L<DBI/fetchall_hashref> for details

See also L<CTK::DBI/tableh>



( run in 1.487 second using v1.01-cache-2.11-cpan-5e09290becf )