DBIx::Class::QueryLog::Transaction - A Transaction


DBIx-Class-QueryLog documentation Contained in the DBIx-Class-QueryLog distribution.

Index


Code Index:

NAME

Top

DBIx::Class::QueryLog::Transaction - A Transaction

SYNOPSIS

Top

Represents a transaction. All queries executed with the context of this transaction are stored herein, as well as a start time, end time and flag for committed or rolledback.

METHODS

Top

new

Create a new DBIx::Class::QueryLog::Transcation

bucket

The bucket this tranaction is in.

queries

Arrayref containing all queries executed, in order of execution.

committed

Flag indicating if this transaction was committed.

rolledback

Flag indicating if this transaction was rolled back.

start_time

Time this transaction started.

end_time

Time this transaction ended.

time_elapsed

Time this transaction took to execute. start - end.

add_to_queries

Add the provided query to this transactions list.

count

Returns the number of queries in this Transaction

get_sorted_queries([ $sql ])

Returns all the queries in this Transaction, sorted by elapsed time. (descending).

If given an argument of an SQL statement, only queries matching that statement will be considered.

AUTHOR

Top

Cory G Watson, <gphat at cpan.org>

ACKNOWLEDGEMENTS

Top

COPYRIGHT & LICENSE

Top


DBIx-Class-QueryLog documentation Contained in the DBIx-Class-QueryLog distribution.
package DBIx::Class::QueryLog::Transaction;
use Moose;

extends 'DBIx::Class::QueryLog::Query';

has committed => (
    is => 'rw',
    isa => 'Bool'
);

has queries => (
    traits => [qw(Array)],
    is => 'rw',
    isa => 'ArrayRef',
    default => sub { [] },
    handles => {
        count => 'count',
        add_to_queries => 'push'
    }
);

has rolledback => (
    is => 'rw',
    isa => 'Bool'
);

sub time_elapsed {
	my $self = shift;

	my $total = 0;
	foreach my $q (@{ $self->queries }) {
		$total += $q->time_elapsed;
	}

	return $total;
}

sub get_sorted_queries {
    my ($self, $sql) = @_;

    my @qs;
    if($sql) {
        @qs = grep({ $_->sql eq $sql } @{ $self->queries });
    } else {
        @qs = @{ $self->queries };
    }

    return [ reverse sort { $a->time_elapsed <=> $b->time_elapsed } @qs ];
}

__PACKAGE__->meta->make_immutable;

1;