diff --git a/.gitignore b/.gitignore index 8b697d3..0cfc470 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,5 @@ inc/ /pm_to_blib /*.zip +# Conf file +/guestbook-ng.conf diff --git a/README.md b/README.md index 46c5303..991eb3f 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/cpanfile b/cpanfile index 92ef292..1c7027e 100644 --- a/cpanfile +++ b/cpanfile @@ -2,3 +2,4 @@ requires 'Test::More'; requires 'Mojo::File'; requires 'Test::Mojo'; requires 'Mojolicious::Lite'; +requires 'Mojo::Pg'; diff --git a/lib/GuestbookNg/Model/Test.pm b/lib/GuestbookNg/Model/Test.pm index dd07bc0..6c4c376 100644 --- a/lib/GuestbookNg/Model/Test.pm +++ b/lib/GuestbookNg/Model/Test.pm @@ -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; diff --git a/templates/test.html.ep b/templates/test.html.ep index 55ebc72..92ea998 100644 --- a/templates/test.html.ep +++ b/templates/test.html.ep @@ -2,7 +2,7 @@ % title 'test';

test page

<% if ($method eq 'POST') { %> -

<%= $string %>

+

<%= $string %> at <%= $time =>

<% } else { %>