Skip to content

Instantly share code, notes, and snippets.

@niner
Created April 2, 2020 18:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niner/13f6f2160ea677cbfaec9855e9c7bdb9 to your computer and use it in GitHub Desktop.
Save niner/13f6f2160ea677cbfaec9855e9c7bdb9 to your computer and use it in GitHub Desktop.
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