Is there a way to connect to a DBIx::Class schema using an existing DBI database handle?
Asked Answered
T

1

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

Terle answered 9/9, 2021 at 11:30 Comment(0)
H
7

I think this will work

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

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

Harter answered 9/9, 2021 at 12:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.