Home > Net >  Is there a way to connect to a DBIx::Class schema using an existing DBI database handle?
Is there a way to connect to a DBIx::Class schema using an existing DBI database handle?

Time:09-17

If I already have an active DBI database handle, is there a way to instantiate a DBIx::Class schema using that database handle, rather than creating a new connection, e.g. something like

my $schema = MyApp::Schema->connect($dbh);

(This is because of some legacy code using some newer DBIC-based code. No, I cannot connect to the schema and pass the schema's database handle to the legacy code, and no, I am not able to rewrite the legacy code to use DBIC.)

CodePudding user response:

I think this will work

my $schema = MyApp::Schema->connect(sub { $dbh });

from perldoc DBIx::Class::Storage::DBI

  • Related