Initial DB implentation (try again)

This commit is contained in:
swag 2021-12-04 18:36:10 -05:00
parent c4bac0c3a7
commit 09ad886737
5 changed files with 50 additions and 5 deletions

2
.gitignore vendored
View File

@ -35,3 +35,5 @@ inc/
/pm_to_blib
/*.zip
# Conf file
/guestbook-ng.conf

View File

@ -4,6 +4,26 @@ The goal of guestbook-ng is to integrate across vendors and customers
with full-service analytics insights by leveraging the latest in Perl
Mojolicious blockchain technologies powered by AI.
## DB Config
$ cat guestbook-ng.conf
{
secrets => ['a_secret_here'],
pg_user => 'guestbooker',
pg_pw => 'a_password_here',
pg_db => 'guestbook'
}
## Testing
$ prove -l t/*.t
t/basic.t .. ok
All tests successful.
Files=1, Tests=6, 1 wallclock secs ( 0.04 usr 0.00 sys + 0.58 cusr 0.05 csys = 0.67 CPU)
Result: PASS
Add the `-v` option for more verbose output
## TODOs
1. All of it
1. Create rows in table

View File

@ -2,3 +2,4 @@ requires 'Test::More';
requires 'Mojo::File';
requires 'Test::Mojo';
requires 'Mojolicious::Lite';
requires 'Mojo::Pg';

View File

@ -4,14 +4,36 @@ package GuestbookNg::Model::Test;
use strict;
use warnings;
use experimental qw{signatures};
use Mojo::Base -base, -signatures;
sub new($class) {
bless {}
has 'pg';
sub new($class, $pg, $object) {
bless {
$pg => $object
}
}
sub test_model($self, $string) {
"you've supplied: $string"
}
sub create_table($self) {
$self->pg->migrations->from_string(
"-- 1 up
CREATE TABLE IF NOT EXISTS messages (
id int,
date timestamp with time zone,
name varchar(255),
msg varchar(255)
);
-- 1 down
DROP TABLE messages;"
)->migrate();
}
sub now($self) {
$self->pg->db->query('SELECT NOW() AS now')->text()
}
1;

View File

@ -2,7 +2,7 @@
% title 'test';
<h1>test page</h1>
<% if ($method eq 'POST') { %>
<p><%= $string %></p>
<p><%= $string %> at <%= $time =></p>
<% } else { %>
<form action="/test" method="post">
<label>Give me string:<br>