DBIx::Cookbook::Recipe::Searching::fetch_all - recipe to fetch all records
Select all records from the actor table, with the option to order by a column.
actor
Sample Usage:
${orm}_cmd fetch_all --order_by last_name # orm = dbic, rdbo, skinny, etc
package DBIx::Cookbook::DBIC::Command::fetch_all; use Moose; extends qw(MooseX::App::Cmd::Command); has order_by => ( traits => [qw(Getopt)], isa => "Str", is => "rw", ); sub execute { my ($self, $opt, $args) = @_; my $where = {}; my $attr = {}; if (my $val = $opt->{order_by}) { $attr->{order_by} = $val; } my $rs = $self->app->schema->resultset('Actor')->search($where, $attr); while (my $row = $rs->next) { use Data::Dumper; my %data = $row->get_columns; warn Dumper(\%data); } } 1;
package DBIx::Cookbook::RDBO::Command::fetch_all; use Moose; extends qw(MooseX::App::Cmd::Command); has order_by => ( traits => [qw(Getopt)], isa => "Str", is => "rw", ); sub execute { my ($self, $opt, $args) = @_; my @attr = $opt->{order_by} ? (sort_by => $opt->{order_by} ) : () ; use Sakila::Actor::Manager; my $result = Sakila::Actor::Manager->get_actor_iterator(@attr); while (my $row = $result->next) { use Data::Dumper; warn Dumper($row->as_tree); } } 1; # Another way to get all rows: # my $result = Sakila::Actor::Manager->get_actor;
package DBIx::Cookbook::Skinny::Command::fetch_all; use Moose; extends qw(MooseX::App::Cmd::Command); has order_by => ( traits => [qw(Getopt)], isa => "Str", is => "rw", ); sub execute { my ($self, $opt, $args) = @_; my @attr = $opt->{order_by} ? (sort_by => $opt->{order_by} ) : () ; use Sakila; my $result = Sakila->search(actor => $opt); while (my $row = $result->next) { use Data::Dumper; warn Dumper($row->{row_data}); } } 1; # Another way to get all rows: # my @rows = Sakila->search...
To install DBIx::Cookbook, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DBIx::Cookbook
CPAN shell
perl -MCPAN -e shell install DBIx::Cookbook
For more information on module installation, please visit the detailed CPAN module installation guide.