Initial DB implementation
This commit is contained in:
parent
067b2918b4
commit
c4bac0c3a7
@ -4,10 +4,33 @@
|
||||
# Daniel Bowling <swaggboi@slackware.uk>
|
||||
|
||||
use Mojolicious::Lite -signatures;
|
||||
use Mojo::Pg;
|
||||
use lib 'lib';
|
||||
use GuestbookNg::Model::Test;
|
||||
|
||||
my $tm = GuestbookNg::Model::Test->new();
|
||||
# Plugins
|
||||
plugin 'Config';
|
||||
|
||||
# Helpers
|
||||
helper pg => sub {
|
||||
state $pg = Mojo::Pg->new(
|
||||
'postgres://' .
|
||||
app->config->{'pg_user'} .
|
||||
':' .
|
||||
app->config->{'pg_pw'} .
|
||||
'@localhost/' .
|
||||
app->config->{'pg_db'}
|
||||
);
|
||||
};
|
||||
|
||||
helper test => sub {
|
||||
state $test = GuestbookNg::Model::Test->new(pg => shift->pg)
|
||||
};
|
||||
|
||||
# Routes
|
||||
under sub ($c) {
|
||||
$c->test->create_table()
|
||||
};
|
||||
|
||||
get '/' => sub ($c) {
|
||||
$c->render()
|
||||
@ -15,9 +38,16 @@ get '/' => sub ($c) {
|
||||
|
||||
any '/test' => sub ($c) {
|
||||
my $method = $c->req->method();
|
||||
my $string = $tm->test_model($c->param('string'));
|
||||
my $time = $c->test->now();
|
||||
my $string =
|
||||
$method eq 'POST' ? $c->test->test_model($c->param('string')) : undef;
|
||||
|
||||
$c->render(method => $method, string => $string);
|
||||
$c->render(
|
||||
method => $method,
|
||||
string => $string,
|
||||
time => $time
|
||||
);
|
||||
};
|
||||
|
||||
# Send it
|
||||
app->start();
|
||||
|
Loading…
x
Reference in New Issue
Block a user