I'm using DBIx::Class in a Catalyst app, and I was wondering if it is possible to make HTML::FormHandler use the same dbh that was already used by DBIx::Class
earlier in the code (perhaps it already does this?). For example:
#connect to db and make query
my $val = $c->model('DB::Example')->search({ condition => 'y'});
my $form = myapp::Form::Example->new;
#now reuse dbh here when updating somehow??
return unless $form->process(
schema => $c->model('DB')->schema,
item_id => $c->user->id,
params => $c->req->params,
);
I know that even if it is creating two database handles it's not gonna kill performance, but I would like to be as concise as I can whenever possible :)
Also, if I were to make to DB calls using DBIx::Class
one after the other, does that reuse the same dbh? Thanks!
Each DBIx::Class::Schema instance has its own dbh. If you fork it will take care to create a new database connection per process as well.
So if you pass the Catalyst model instance to Formhandler it will reuse the dbh.