[Catalyst] Where and how to access database
Jason Kohles
email at jasonkohles.com
Wed Mar 21 13:04:07 GMT 2007
On Mar 21, 2007, at 7:43 AM, Mario Minati wrote:
> Am Mittwoch 21 März 2007 11:39 schrieb Stephan Austermühle:
>
>>
>> The database tables are being loaded dynamically by
>> Catalyst::Model::DBIC::Schema/ DBIx::Class::Schema::Loader. I read
>> that I
>> can get the DBH via $schema->storage->dbh -- but where do I get
>> $schema
>> from?
>
my $dbh = $c->model( 'MyModel' )->schema->storage->dbh;
Just be sure you don't hold onto the handle for too long, or strange
things can happen (especially in a persistent environment).
>
> In the table class I can create custom functions to alter or get the
> resultsets.
>
> How complex can a query be that you want the DBI handle?
> With DBIC you can do almost everything, e.g. multi table joins,
> creating
> aliases with user defined functions and procedures.
> At least for me that's all I want :)
>
There is at least one thing that I've used this for that DBIx::Class
can't do (or at least I couldn't figure out how at the time I needed
to do it)...
$c->model( 'MyModel' )->schema->storage->dbh->do( "NOTIFY
update_listener" );
--
Jason Kohles
email at jasonkohles.com
http://www.jasonkohles.com/
"A witty saying proves nothing." -- Voltaire
More information about the Catalyst
mailing list