1 package DBIx::Class::Storage::DBI::SetConstraintsDeferred;
6 use base 'DBIx::Class::Storage::DBI';
10 use Context::Preserve 'preserve_context';
16 DBIx::Class::Storage::DBI::SetConstraintsDeferred - Storage component for deferred constraints via C<SET CONSTRAINTS>
20 This component implements L<DBIx::Class::Storage::DBI/with_deferred_fk_checks>
21 by wrapping the the coderef in C<SET CONSTRAINTS ALL DEFERRED> and
22 C<SET CONSTRAINTS ALL IMMEDIATE>.
26 sub with_deferred_fk_checks {
27 my ($self, $sub) = @_;
29 my $txn_scope_guard = $self->txn_scope_guard;
31 $self->_do_query('SET CONSTRAINTS ALL DEFERRED');
33 return preserve_context {
34 my $inner_self = $self; # avoid nested closure leak on 5.8
35 my $sg = Scope::Guard->new(sub {
36 $inner_self->_do_query('SET CONSTRAINTS ALL IMMEDIATE');
39 } after => sub { $txn_scope_guard->commit };
42 =head1 FURTHER QUESTIONS?
44 Check the list of L<additional DBIC resources|DBIx::Class/GETTING HELP/SUPPORT>.
46 =head1 COPYRIGHT AND LICENSE
48 This module is free software L<copyright|DBIx::Class/COPYRIGHT AND LICENSE>
49 by the L<DBIx::Class (DBIC) authors|DBIx::Class/AUTHORS>. You can
50 redistribute it and/or modify it under the same terms as the
51 L<DBIx::Class library|DBIx::Class/COPYRIGHT AND LICENSE>.