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

30 lines
583 B
Perl
Raw Normal View History

2022-02-09 20:15:52 -05:00
#!/usr/bin/env perl
package GuestbookNg::Model::Counter;
use Mojo::Base -base, -signatures;
has 'pg';
sub new($class, $pg, $pg_object) {
2022-02-09 21:14:15 -05:00
bless {$pg => $pg_object}
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')->text()
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;