5

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.)

Rob
  • 781
  • 5
  • 19

1 Answers1

7

I think this will work

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

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

JGNI
  • 3,933
  • 11
  • 21