File Coverage

blib/lib/Mojolicious/resources/templates/mojo/command/resources/m_class.ep
Criterion Covered Total %
statement 12 12 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 16 16 100.0


line stmt bran cond sub pod time code
1 2     2   9000 % my $a = shift;
  2     2   7  
  2     2   16  
  2     2   252  
  2         5  
  2         887  
  2         6807  
  2         5  
  2         11  
  2         167  
  2         5  
  2         720  
2             package <%= $a->{class} %>;
3             use Mojo::Base -base, -signatures;
4              
5             has '<%= $a->{db_helper} %>';
6              
7             sub add($self, $row) {
8             return $self-><%= $a->{db_helper} %>->db->insert('<%= $a->{t} %>', $row)->last_insert_id;
9             }
10              
11             sub all($self, $opts = {}) {
12             $opts->{limit} //= 100;
13             $opts->{limit} = 100 unless $opts->{limit} =~/^\d+$/;
14             $opts->{offset} //= 0;
15             $opts->{offset} = 0 unless $opts->{offset} =~/^\d+$/;
16             state $abstr = $self-><%= $a->{db_helper} %>->abstract;
17             my ($sql, @bind) = $abstr->select('<%= $a->{t} %>', '*', $opts->{where}//());
18             $sql .= " LIMIT $opts->{limit}" . ($opts->{offset} ? " OFFSET $opts->{offset}" : '');
19             return $self-><%= $a->{db_helper} %>->db->query($sql, @bind)->hashes->to_array;
20             }
21              
22             sub find($self, $id) {
23             return $self-><%= $a->{db_helper} %>->db->select('<%= $a->{t} %>', undef, {id => $id})->hash;
24             }
25              
26             sub remove($self, $id) {
27             return $self-><%= $a->{db_helper} %>->db->delete('<%= $a->{t} %>', {id => $id});
28             }
29              
30             sub save($self, $id, $row) {
31             return $self-><%= $a->{db_helper} %>->db->update('<%= $a->{t} %>', $row, {id => $id});
32             }
33              
34             1;