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) {
|
2022-04-22 12:44:19 -04:00
|
|
|
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) {
|
2022-04-03 21:34:22 -04:00
|
|
|
$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;
|