App-Environ-Mojo-Pg

 view release on metacpan or  search on metacpan

lib/App/Environ/Mojo/Pg.pm  view on Meta::CPAN


our $VERSION = '0.2';

use strict;
use warnings;
use v5.10;
use utf8;

use App::Environ;
use App::Environ::Config;
use Params::Validate qw(validate_pos);
use URI;
use Mojo::Pg;

my %PG;

App::Environ::Config->register(qw(pg.yml));

sub pg {
  my $class = shift;

  my ($connector) = validate_pos( @_, 1 );

  unless ( defined $PG{$connector} ) {
    my $pg_string = $class->pg_string($connector);
    $PG{$connector} = Mojo::Pg->new($pg_string);

    my $conf = App::Environ::Config->instance->{pg}{connectors}{$connector};

    if ( $conf->{max_connections} ) {
      $PG{$connector}->max_connections( $conf->{max_connections} );
    }

lib/App/Environ/Mojo/Pg.pm  view on Meta::CPAN

      $PG{$connector}->migrations->from_file( $conf->{migrations}{file} );
    }
  }

  return $PG{$connector};
}

sub pg_string {
  my $class = shift;

  my ($connector) = validate_pos( @_, 1 );

  my $conf = App::Environ::Config->instance->{pg}{connectors}{$connector};

  my $url = URI->new();

  ## Non standart schema workaround
  ## For URI objects that do not belong to one of these, you can only use the common and generic methods.
  $url->scheme('https');

  $url->userinfo("$conf->{user}:$conf->{password}");



( run in 0.509 second using v1.01-cache-2.11-cpan-a5abf4f5562 )