Created
April 2, 2020 18:15
-
-
Save niner/13f6f2160ea677cbfaec9855e9c7bdb9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unit class API::v1::Model; | |
use Inline::Perl5; | |
my $gil = Lock.new; | |
has @.connect_info; | |
has $!schema; | |
method schema() { | |
$!schema //= $.schema-from-thread; | |
} | |
method schema-from-thread() { | |
my role Perl5SchemaConnector { | |
has $.p5 = Inline::Perl5.new; | |
has $.schema is rw; | |
} | |
my $thread = $*THREAD; | |
unless $thread.does(Perl5SchemaConnector) { | |
$gil.protect: { | |
$thread does Perl5SchemaConnector; | |
$thread.p5.use('Atikon::DB::Timemngt'); | |
$thread.p5.use('DBD::Pg'); | |
$thread.p5.use('DBIx::Class::Storage::DBI'); | |
my Str $db_dsn = @!connect_info[0]; | |
my Str $db_user = @!connect_info[1]; | |
my Str $db_pass = @!connect_info[2]; | |
$thread.schema = $thread.p5.invoke( | |
'Atikon::DB::Timemngt', 'connect', $db_dsn, $db_user, $db_pass | |
); | |
} | |
} | |
return $thread.schema; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment