Data::Stream::Bulk::DBI - N-at-a-time iteration of L<DBI> statement results.


Data-Stream-Bulk documentation Contained in the Data-Stream-Bulk distribution.

Index


Code Index:

NAME

Top

Data::Stream::Bulk::DBI - N-at-a-time iteration of DBI statement results.

SYNOPSIS

Top

    use Data::Stream::Bulk::DBI;

    my $sth = $dbh->prepare("SELECT hate FROM sql"); # very big resultset
    $sth->execute;

    return Data::Stream::Bulk::DBI->new(
        sth => $sth,
        max_rows => $n, # how many at a time
        slice => [ ... ], # if you want to pass the first param to fetchall_arrayref
    );

DESCRIPTION

Top

This implementation of Data::Stream::Bulk api works with DBI statement handles, using fetchall_arrayref in DBI.

It fetches max_rows at a time (defaults to 500).

ATTRIBUTES

Top

sth

The statement handle to call fetchall_arrayref on.

slice

Passed verbatim as the first param to fetchall_arrayref. Should usually be undef, provided for completetness.

max_rows

The second param to fetchall_arrayref. Controls the size of each buffer.

Defaults to 500.

METHODS

Top

get_more

See Data::Stream::Bulk::DoneFlag.

Calls fetchall_arrayref to get the next chunk of rows.

all

Calls fetchall_arrayref to get the raminder of the data (without specifying max_rows).

AUTHOR

Top

Yuval Kogman <nothingmuch@woobling.org>

COPYRIGHT AND LICENSE

Top


Data-Stream-Bulk documentation Contained in the Data-Stream-Bulk distribution.

package Data::Stream::Bulk::DBI;
BEGIN {
  $Data::Stream::Bulk::DBI::AUTHORITY = 'cpan:NUFFIN';
}
BEGIN {
  $Data::Stream::Bulk::DBI::VERSION = '0.08';
}
# ABSTRACT: N-at-a-time iteration of L<DBI> statement results.

use Moose;

use namespace::clean -except => 'meta';

with qw(Data::Stream::Bulk::DoneFlag) => { -excludes => [qw/is_done all finished/] };

has sth => (
    isa => "Object",
    is  => "ro",
    required => 1,
    handles => [qw(fetchall_arrayref)],
    clearer => "finished",
);

has slice => (
    is  => "ro",
);

has max_rows => (
    isa => "Int",
    is  => "rw",
    default => 500,
);

sub get_more {
    my $self = shift;
    $self->fetchall_arrayref( $self->slice, $self->max_rows );
}

sub all {
    my $self = shift;

    my $all = $self->fetchall_arrayref( $self->slice );

    $self->_set_done;

    return @$all;
}

__PACKAGE__->meta->make_immutable;

__PACKAGE__;



__END__