[Dbix-class] Detecting connection errors

Alberto Luaces aluaces at udc.es
Wed Oct 14 19:01:55 GMT 2015


ilmari at ilmari.org (Dagfinn Ilmari Mannsåker) writes:

> Alberto Luaces <aluaces at udc.es> writes:
>
>> Hi,
>>
>> I stumped over a problem when learning to use DBIx::Class.  I had a typo
>> on the filename holding the database, but no exception was thrown until
>> I wanted to retrieve some results, which was not intuitive for me.  How
>> do you check for a successful connection?
>
> First of all, you never need to do "or die ..." with DBIx::Class
> operations, since they always throw exceptions on error.
>

Ok. I was just trying after realizing no exception was happening.
Actually I was using the autodie module in the beginning.

>
> Sencondly, DBIx::Class only hits the database when it absolutely has
>to,
> e.g. to fetch restults.  This includes the initial connection.  However,
> you can force it to connect early by calling
>
>    $schema->storage->ensure_connected;
>
> Which will throw an exception if it fails to connect.

Yes, it sounds sensible for an ORM to be lazy, but I did not imagine
that it could even involve connections.  Thanks a lot for the pointer.

-- 
Alberto




More information about the DBIx-Class mailing list