guestbook-ng/lib/GuestbookNg/Model/Counter.pm

28 lines
562 B
Perl
Raw Normal View History

2022-02-09 20:15:52 -05:00
package GuestbookNg::Model::Counter;
use Mojo::Base -base, -signatures;
has 'pg';
sub new($class, $pg, $pg_object) {
bless {$pg => $pg_object}, $class
2022-02-09 20:15:52 -05:00
}
sub get_visitor_count($self) {
$self->pg->db->query(<<~'END_SQL')->text()
2022-02-09 21:02:35 -05:00
SELECT counter_value
2022-02-09 20:15:52 -05:00
FROM counters
2022-02-09 21:02:35 -05:00
WHERE counter_name = 'visitor';
2022-02-09 20:15:52 -05:00
END_SQL
}
sub increment_visitor_count($self) {
$self->pg->db->query(<<~'END_SQL')
2022-02-09 20:15:52 -05:00
UPDATE counters
2022-02-09 21:02:35 -05:00
SET counter_value = counter_value + 1
WHERE counter_name = 'visitor';
2022-02-09 20:15:52 -05:00
END_SQL
}
1;