[Dbix-class] Detecting connection errors
Alberto Luaces
aluaces at udc.es
Wed Oct 14 19:14:34 GMT 2015
Alberto Luaces <aluaces at udc.es> writes:
>> 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.
Oops, I spoke too soon. ensure_connected is not throwing. Here is the
code for reference:
1 use lib './lib';
2 use DAAO;
3
4 my $r = DAAO->connect("dbi:SQLite:non-existent.db");
5 $r->storage->ensure_connected;
6
7 my $resultset = $r->resultset('Alumno')->search;
8
9 my $person = $resultset->next; # Iterator
10
11 print $person->asistencia;
It does not crash until line 9, when the iterator is used.
--
Alberto
More information about the DBIx-Class
mailing list