Pooru/lib/Pooru/API/V0/Model/Results.pm
Lucas Gabriel Vuotto 0635e37e13 api/v0: add a new model implementation
Use DBI exclusively to have a fine control of the produced queries. dbic
requires a lot of symbols permutation to produce the desired ones.
2025-05-03 13:30:27 +00:00

30 lines
512 B
Perl

package Pooru::API::V0::Model::Results;
use v5.40;
sub new ($class, $sth, $slice, @bind_values)
{
my $self = {
_sth => $sth,
_slice => $slice,
_bind_values => [@bind_values],
};
return bless $self, $class;
}
sub fetchall ($self, $slice = $self->{_slice})
{
$self->{_sth}->execute($self->{_bind_values}->@*);
return $self->{_sth}->fetchall_arrayref($slice);
}
sub single ($self, $slice = $self->{_slice})
{
my $rows = $self->fetchall($slice);
return $rows->@* == 1 ? $rows->[0] : undef;
}
1;