[Catalyst] How safe are database transactions?
Ash Berlin
ash_cpan at firemirror.com
Thu Jan 4 11:11:10 GMT 2007
Xavier Robin wrote:
> Hello all,
>
> I'm sorry if it is the wrong list, but I thought it was more a
> Catalyst-specific issue than a DBIx::Class one, as it is about the way
> Catalyst uses DBIx::Class.
>
> I would like to use transactions in Catalyst.
>
> my $transaction = $c->model('MyAppDB')->storage;
> $transaction->txn_begin;
> eval {
> # Do some insertions with $c->model('MyAppDB::Table')->create()
> };
> if ($@) {
> $transaction->txn_rollback;
> }
> else {
> $transaction->txn_commit;
> }
>
$c->model('MyAppDB')->txn_do(sub {
# Do some insertions here....
});
That will handle rollback/commit for you - I've never noticed any
problems, but them I've not done much multiuser testing yet.
Ash
More information about the Catalyst
mailing list