Acrux-DBI

 view release on metacpan or  search on metacpan

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

    # 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>

=head2 hashes

    my $hashes = $res->hashes;

Fetch all rows from L</"sth"> and return them as an array containing hash references

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

=head2 last_insert_id

    my $last_id = $res->last_insert_id;

That value of C<AUTO_INCREMENT> column if executed query was C<INSERT> in a table with
C<AUTO_INCREMENT> column

=head2 more_results

    do {
      my $columns = $res->columns;
      my $arrays = $res->arrays;
    } while ($res->more_results);

Handle multiple results

=head2 rows

    my $num = $res->rows;

Number of rows

=head2 state



( run in 0.476 second using v1.01-cache-2.11-cpan-5735350b133 )