Advertisement
Guest User

Untitled

a guest
Jun 11th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.89 KB | None | 0 0
  1. package OpenExodus::Model::Schema;
  2. use strict;
  3. use warnings;
  4.  
  5. use Fey::DBIManager::Source;
  6. use Fey::Loader;
  7. use YAML qw/LoadFile/;
  8. use Fey::ORM::Schema;
  9. use Moose;
  10. use MooseX::ClassAttribute;
  11.  
  12. class_has config => (
  13.     isa => 'Hash',
  14.     is => 'ro',
  15.     default => sub {
  16.         my $file = $ENV{'DB_CONF'} || 'dbconf.yaml';
  17.         return LoadFile( $file ) if -e $file;
  18.         return {};
  19.     },
  20. );
  21.  
  22. sub dbh {
  23.     my $class = shift;
  24.     return $class->DBIManager()->default_source->dbh;
  25. }
  26.  
  27. __PACKAGE__->DBIManager()->add_source(
  28.     Fey::DBIManager::Source->new(
  29.         dsn      => 'dbi:Pg:dbname=' . ($ENV{DB} || __PACKAGE__->config->{database}),
  30.         username => $ENV{DB_USER} || __PACKAGE__->config->{username},
  31.         password => $ENV{DB_PASS} || __PACKAGE__->config->{password},
  32.     )  
  33. );
  34.  
  35. has_schema( Fey::Loader->new( dbh => __PACKAGE__->dbh() )->make_schema() );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement