| 1 | package DBIx::Class::ResultSet::PgLog; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | use base "DBIx::Class::ResultSet"; | ||
| 7 | |||
| 8 | =head1 NAME | ||
| 9 | |||
| 10 | DBIx::Class::ResultSet::PgLog - ResultSet base class for DBIx::Class::PgLog | ||
| 11 | |||
| 12 | =head1 VERSION | ||
| 13 | |||
| 14 | version 0.1 | ||
| 15 | |||
| 16 | =head1 SYNOPSIS | ||
| 17 | |||
| 18 | Either create your own resultset-classes for each audited result-class, and load | ||
| 19 | PgLogs resultset-component: | ||
| 20 | |||
| 21 | package MySchema::ResultSet::MyAuditedSource; | ||
| 22 | |||
| 23 | use base "DBIx::Class::ResultSet"; # or use Moose and MooseX::NonMoose; | ||
| 24 | |||
| 25 | __PACKAGE__->load_components("ResultSet::PgLog"); | ||
| 26 | |||
| 27 | Or set the default resultset-class in your Schema: | ||
| 28 | |||
| 29 | package MySchema; | ||
| 30 | |||
| 31 | use base "DBIx::Class::Schema"; | ||
| 32 | |||
| 33 | ... | ||
| 34 | |||
| 35 | __PACKAGE__->load_namespaces( | ||
| 36 | default_resultset_class => "PgLog" | ||
| 37 | ); | ||
| 38 | |||
| 39 | =head1 DESCRIPTION | ||
| 40 | |||
| 41 | This resultset class enables logging for database updates made by calling | ||
| 42 | L<DBIx::Class::ResultSet/delete> and L<DBIx::Class::ResultSet/update>. | ||
| 43 | This includes any updates made by methods which rely on the above, like | ||
| 44 | L<DBIx::Class::Relationship::Base/set_\$rel>. | ||
| 45 | |||
| 46 | If you want full logging in a relational database, you most likely want to use this | ||
| 47 | component. | ||
| 48 | |||
| 49 | =head2 NOTE: | ||
| 50 | |||
| 51 | The current implementation enables logging in the resultset by simply delegating | ||
| 52 | 'delete' and 'update' to 'delete_all' and 'update_all', which call the required triggers. | ||
| 53 | As a result, a database query like | ||
| 54 | |||
| 55 | "DELETE FROM table WHERE id IN '1', '2', '3'" | ||
| 56 | |||
| 57 | will result in 3 atomic queries: | ||
| 58 | |||
| 59 | "DELETE FROM table WHERE id = '1'"; | ||
| 60 | "DELETE FROM table WHERE id = '2'"; | ||
| 61 | "DELETE FROM table WHERE id = '3'"; | ||
| 62 | |||
| 63 | which is much slower. It is therefore recommended to use this module only for resultset classes where it is needed. | ||
| 64 | Specifying this module as default resultset class is only recommended if logging is needed for all tables. | ||
| 65 | |||
| 66 | |||
| 67 | =head1 L<DBIx::Class::ResultSet> OVERRIDDEN METHODS | ||
| 68 | |||
| 69 | =head2 delete | ||
| 70 | |||
| 71 | Calls L<DBIx::Class::ResultSet/delete_all> to ensure that triggers defined by | ||
| 72 | L<DBIx::Class::PgLog> are run. | ||
| 73 | |||
| 74 | =cut | ||
| 75 | |||
| 76 | sub delete { | ||
| 77 | shift->delete_all; | ||
| 78 | }; | ||
| 79 | |||
| 80 | =head2 update | ||
| 81 | |||
| 82 | Calls L<DBIx::Class::ResultSet/update_all> to ensure that triggers defined by | ||
| 83 | L<DBIx::Class::PgLog> are run. | ||
| 84 | |||
| 85 | =cut | ||
| 86 | |||
| 87 | sub update { | ||
| 88 | shift->update_all(@_); | ||
| 89 | } | ||
| 90 | |||
| 91 | =head1 AUTHORS | ||
| 92 | |||
| 93 | See L<DBIx::Class::PgLog/AUTHOR> and L<DBIx::Class::PgLog/CONTRIBUTORS> | ||
| 94 | |||
| 95 | =head1 COPYRIGHT AND LICENSE | ||
| 96 | |||
| 97 | This software is copyright (c) 2012 by Mark Jubenville. | ||
| 98 | |||
| 99 | This is free software; you can redistribute it and/or modify it under | ||
| 100 | the same terms as the Perl 5 programming language system itself. | ||
| 101 | |||
| 102 | =cut | ||
| 103 | 1; | ||
| 104 | |||
| 105 |