2021-12-05 04:06:05 +00:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
|
|
|
|
package GuestbookNg::Model::Message;
|
|
|
|
|
|
|
|
use Mojo::Base -base, -signatures;
|
|
|
|
|
|
|
|
has 'pg';
|
|
|
|
|
|
|
|
sub new($class, $pg, $object) {
|
|
|
|
bless {$pg => $object}
|
|
|
|
}
|
|
|
|
|
2021-12-05 07:52:31 +00:00
|
|
|
sub get_posts($self) {
|
|
|
|
$self->pg->db->query('SELECT date, name, msg FROM messages;')->arrays()
|
|
|
|
}
|
|
|
|
|
|
|
|
sub send_post($self, $name, $msg) {
|
|
|
|
$self->pg->db->query(
|
|
|
|
'INSERT INTO messages (date, name, msg)
|
|
|
|
VALUES (NOW(), ?, ?);', $name, $msg
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-12-05 04:06:05 +00:00
|
|
|
1;
|