NAME
Test::DBChanges::TableChangeSet - set of changes to one DB table
VERSION
version 1.0.2
SYNOPSIS
my $dbchanges = Test::DBChanges::Pg->new({
dbh => $dbh,
source_names => [qw(things ledger)],
});
# later:
my $changeset = $dbchanges->changeset_for_code(sub { do_something($dbh) });
for my $row ($changeset->changes_for_source('things')->inserted_rows->@*) {
# $row is a hashref with the inserted data
}
DESCRIPTION
Instances of this class are instantiated by Test::DBChanges::ChangeSet
. They contain all the data needed to construct hashrefs or objects for each inserted / updated / deleted row in one table.
ATTRIBUTES
table_name
Name of the table this set of changes refer to.
source_name
Name of the source this set of changes refer to. For some DBChanges classes (e.g. Test::DBChanges::Pg::DBIC
) the source name is different from the table name.
inserted_rows
Arrayref of row objects, one for each newly-inserted row. The corresponding rows might not be in the database at all: they may have been deleted, for example.
updated_rows
Arrayref of row objects, one for each updated row. You may get multiple objects for the "same" row, one for each "UPDATE" operation.
deleted_rows
Arrayref of row objects, one for each deleted row. The corresponding rows are obviously not in the db.
combined_rows
my @rows = $table_changeset->combined_rows->@*;
# same thing
my @rows = $table_changeset->combined_rows('id')->@*;
# different primary key column
my @other_rows = $other_table_changeset->combined_rows('primary')->@*;
If you don't need to know each separate insert / update / delete, but only care about the resulting rows, you can use this method. It needs a primary key column (defaults to id
) to match different operations to the "same" row.
AUTHOR
Gianni Ceccarelli <gianni.ceccarelli@broadbean.com>
COPYRIGHT AND LICENSE
This software is copyright (c) 2019 by BroadBean UK, a CareerBuilder Company.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.