[Catalyst] sql debugging hooks
Minty
mintywalker at gmail.com
Sat Jul 11 18:45:08 GMT 2009
Hi,
I'm trying to create some hooks to make it easy to see what sql
queries are being run by any particular catalyst request.
I have:
package My::Schema;
use base qw/DBIx::Class::Schema/;
and then Schema/Employee.pm module, etc:
package My::Schema::Employee;
use base qw/DBIx::Class/;
...
I also have:
package My::Model::DB;
use base qw/Catalyst::Model::DBIC::Schema/;
__PACKAGE__->config(schema_class => 'My::Schema');
as described in Catalyst::Model::DBIC::Schema, so that in my Catalyst
Controllers I can do:
my $model = $c->model('DB::Employee');
And that all works, I can run queries against it and the connection
details are magically loaded from my.conf.
Then, for debugging sql queries, I have:
package My::Model::Debugger;
use base qw<DBIx::Class::Storage::Statistics>;
sub query_start { ... }
Now currently I have this in a Controller module:
my $debugger = My::Model::Debugger->new();
my $model = $c->model('DB::Employee');
$model->result_source->storage->debugobj($debugger);
$model->result_source->storage->debug(1);
my $employee = $mode->find(123);
$model->result_source->storage->debug(0);
Which results in my query_start method being called with the sql being run and
the parameters for it. Which is what I was after.
But I want to inject my $debugger via the Model or schema, and
enable/disable it globablly via a configuration file flag.
I'm a bit lost as to where/how I can do that. Any pointers?
More information about the Catalyst
mailing list