/
ByName.pm
40 lines (29 loc) · 986 Bytes
/
ByName.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package MusicBrainz::Server::Data::Statistics::ByName;
use Moose;
use namespace::autoclean;
use namespace::autoclean;
use MusicBrainz::Server::Data::Utils qw( placeholders );
use MusicBrainz::Server::Entity::Statistics::ByName;
extends 'MusicBrainz::Server::Data::Entity';
with 'MusicBrainz::Server::Data::Role::Sql';
sub _table { 'statistics.statistic' }
sub _columns { 'id, date_collected, name, value' }
sub _entity_class
{
return 'MusicBrainz::Server::Entity::Statistics::ByName';
}
sub get_statistic {
my ($self, $statistic) = @_;
my $query = "SELECT " . $self->_columns . "
FROM " . $self->_table . "
WHERE name = ?";
my @stats = @{ $self->sql->select_list_of_hashes($query, $statistic) };
my $stats = MusicBrainz::Server::Entity::Statistics::ByName->new(
name => $statistic,
);
for my $row (@stats) {
$stats->data->{$row->{date_collected}} = $row->{value};
}
return $stats;
}
1;