Use heredoc for SQL queries

This commit is contained in:
swagg boi 2021-12-21 23:57:48 -05:00
parent 76d7e75eb8
commit 94523eeba9

View file

@ -14,21 +14,24 @@ sub new($class, $pg, $pg_object) {
} }
sub get_posts($self) { sub get_posts($self) {
$self->pg->db $self->pg->db->query(<<~'END_SQL')->arrays()
->query('SELECT to_char( SELECT to_char(message_date, 'Dy Mon DD HH:MI:SS AM TZ YYYY'),
message_date, visitor_name,
\'Dy Mon DD HH:MI:SS AM TZ YYYY\' message
), FROM messages
visitor_name, message ORDER BY message_date DESC;
FROM messages END_SQL
ORDER BY message_date DESC;')->arrays()
} }
sub create_post($self, $name, $message) { sub create_post($self, $name, $message) {
$self->pg->db->query( $self->pg->db->query(
'INSERT INTO messages (message_date, visitor_name, message) 'INSERT INTO messages (message_date, visitor_name, message)
VALUES (NOW(), ?, ?);', $name, $message VALUES (NOW(), ?, ?);', $name, $message
) );
$self->pg-db->query(<<~'END_SQL', $name, $message);
INSERT INTO messages (message_date, visitor_name, message)
VALUES (NOW(), ?, ?);
END_SQL
} }
sub view_posts($self, $this_page, $last_page = undef, @posts) { sub view_posts($self, $this_page, $last_page = undef, @posts) {