I'm trying to write a Rose::DB::Object query string using either an Array or a Hash, however I'm unsure how to do it. I'm trying to write an update function based off of certain ID's in a list that are enumerated in the array. I unfortunately do not have any other unique key to filter on to build the query, so I need to query specific ID's.
Essentially I am trying to programatically write the follow:
my $list = My::DB::Manager->get_items(query => [
{id => 1},
{id => 14},
{id => 210},
{id => 1102},
{id => 3151},
]);
This is the code I have so far, but I haven't been able to successfully achieve what I am trying to do:
use My::DB::Manager;
my @ary;
foreach (@_) {
my %col = ("id", $_);
push (@ary, \%col);
}
my $list = My::DB::Manager->get_items(query => \@ary);
...
./test.pl
Now the script just hangs with no output indefinately.
I'm trying to avoid iterating through the DB::Manager and making a DB call on a per record basis as this script will be run via cron every 60 seconds and has the potential to return large sets.
The query
parameter takes a reference to an array of name/value pairs, not a reference to an array of hash references. If you want objects where the value of the id
column is one of a list of values, then use the name id
and a reference to an array of ids as the value. This code should work (assuming the id values are in @_
):
$list = My::DB::Manager->get_items(query => [ id => \@_ ]);