2022-02-10 01:15:52 +00:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
|
|
|
|
package GuestbookNg::Model::Counter;
|
|
|
|
|
|
|
|
use Mojo::Base -base, -signatures;
|
|
|
|
|
|
|
|
has 'pg';
|
|
|
|
|
|
|
|
sub new($class, $pg, $pg_object) {
|
2022-02-10 02:14:15 +00:00
|
|
|
bless {$pg => $pg_object}
|
2022-02-10 01:15:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub get_visitor_count($self) {
|
|
|
|
$self->pg->db->query(<<~'END_SQL')->text()
|
2022-02-10 02:02:35 +00:00
|
|
|
SELECT counter_value
|
2022-02-10 01:15:52 +00:00
|
|
|
FROM counters
|
2022-02-10 02:02:35 +00:00
|
|
|
WHERE counter_name = 'visitor';
|
2022-02-10 01:15:52 +00:00
|
|
|
END_SQL
|
|
|
|
}
|
|
|
|
|
|
|
|
sub increment_visitor_count($self) {
|
2022-04-04 01:34:22 +00:00
|
|
|
$self->pg->db->query(<<~'END_SQL')
|
2022-02-10 01:15:52 +00:00
|
|
|
UPDATE counters
|
2022-02-10 02:02:35 +00:00
|
|
|
SET counter_value = counter_value + 1
|
|
|
|
WHERE counter_name = 'visitor';
|
2022-02-10 01:15:52 +00:00
|
|
|
END_SQL
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|