Refactor schema into attribute

This commit is contained in:
Tom Bloor 2017-04-05 22:43:08 +01:00
parent 1b55fbeeca
commit a6e282ebb5

View file

@ -10,6 +10,14 @@ use Authen::Passphrase::BlowfishCrypt;
use Scalar::Util qw(looks_like_number); use Scalar::Util qw(looks_like_number);
use Pear::LocalLoop::Schema; use Pear::LocalLoop::Schema;
has schema => sub {
my $c = shift;
return Pear::LocalLoop::Schema->connect(
$c->app->config->{dsn},
$c->app->config->{user},
$c->app->config->{pass},
);
};
sub startup { sub startup {
my $self = shift; my $self = shift;
@ -25,18 +33,15 @@ $self->plugin( 'Config', {
my $config = $self->config; my $config = $self->config;
my $schema = Pear::LocalLoop::Schema->connect($config->{dsn},$config->{user},$config->{pass}) or die "Could not connect";
my $dbh = $schema->storage->dbh;
$dbh->do("PRAGMA foreign_keys = ON");
$dbh->do("PRAGMA secure_delete = ON");
my $sessionTimeSeconds = 60 * 60 * 24 * 7; #1 week. my $sessionTimeSeconds = 60 * 60 * 24 * 7; #1 week.
my $sessionTokenJsonName = 'sessionToken'; my $sessionTokenJsonName = 'sessionToken';
my $sessionExpiresJsonName = 'sessionExpires'; my $sessionExpiresJsonName = 'sessionExpires';
# shortcut for use in template # shortcut for use in template
$self->helper( db => sub { $dbh }); $self->helper( db => sub { $self->app->schema->storage->dbh });
$self->helper( schema => sub { $schema }); $self->helper( schema => sub { $self->app->schema });
my $r = $self->routes; my $r = $self->routes;
$r = $r->any('/api') if $self->app->mode ne 'testing'; $r = $r->any('/api') if $self->app->mode ne 'testing';