| 1 | package DBIO::PostgreSQL::Async::TransactionContext; | ||||||||||||||||||||||
| 2 | # ABSTRACT: Pinned connection context for an async PostgreSQL transaction | ||||||||||||||||||||||
| 3 | |||||||||||||||||||||||
| 4 | 5 | ▶ | use strict; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 5 | 5 | ▶ | use warnings; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 6 | 5 | ▶ | use Future (); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 7 | 5 | ▶ | use namespace::clean; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 8 | |||||||||||||||||||||||
| 9 | sub new { | ||||||||||||||||||||||
| 10 | 1 | ▶ | my ($class, %args) = @_; | ||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=12.0
Pod
undocumented
| |||||||||||||||||||||||
| 11 | return bless { | ||||||||||||||||||||||
| 12 | storage => $args{storage} // die('storage required'), | ||||||||||||||||||||||
| 13 | 1 | ▶ | pg => $args{pg} // die('pg required'), | ||||||||||||||||||||
|
Condition50%2/4
$args{"storage"} // die("storage required")
$args{"pg"} // die("pg required")
MC/DC0%0/1
$args{"storage"} // die("storage required")
$args{"storage"}
MC/DC0%0/1
$args{"pg"} // die("pg required")
$args{"pg"}
Truth table50%1/2
A
A= $args{"storage"}
Truth table50%1/2
A
A= $args{"pg"}
| |||||||||||||||||||||||
| 14 | }, $class; | ||||||||||||||||||||||
| 15 | } | ||||||||||||||||||||||
| 16 | |||||||||||||||||||||||
| 17 | |||||||||||||||||||||||
| 18 | 0 | ▶ | sub storage { $_[0]->{storage} } | ||||||||||||||||||||
|
Subroutine
storage: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||
| 19 | |||||||||||||||||||||||
| 20 | |||||||||||||||||||||||
| 21 | 1 | ▶ | sub txn_pg { $_[0]->{pg} } | ||||||||||||||||||||
|
Subroutine
txn_pg: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||
| 22 | |||||||||||||||||||||||
| 23 | |||||||||||||||||||||||
| 24 | 1 | ▶ | sub pool { $_[0]->{storage}->pool } | ||||||||||||||||||||
|
Subroutine
pool: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||
| 25 | |||||||||||||||||||||||
| 26 | |||||||||||||||||||||||
| 27 | 1 | ▶ | sub in_txn { 1 } | ||||||||||||||||||||
|
Subroutine
in_txn: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||
| 28 | |||||||||||||||||||||||
| 29 | |||||||||||||||||||||||
| 30 | sub _query_async { | ||||||||||||||||||||||
| 31 | 1 | ▶ | my ($self, $sql, $bind) = @_; | ||||||||||||||||||||
|
Subroutine
_query_async: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 32 | 1 | return $self->{storage}->_query_async_pinned($self->{pg}, $sql, $bind); | |||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||
| 34 | |||||||||||||||||||||||
| 35 | # CRUD inside a transaction MUST run on the pinned connection that | ||||||||||||||||||||||
| 36 | # BEGIN/COMMIT ran on, not a fresh pooled one. Each method routes | ||||||||||||||||||||||
| 37 | # through the storage's shared CRUD builder with the pinned connection, | ||||||||||||||||||||||
| 38 | # so SQL generation (insert RETURNING, select_single first-row) is not | ||||||||||||||||||||||
| 39 | # duplicated. Forwarding to $storage->select_async etc. would acquire a | ||||||||||||||||||||||
| 40 | # separate pool connection and run the query OUTSIDE the transaction. | ||||||||||||||||||||||
| 41 | 1 | ▶ | sub select_async { my $self = shift; $self->{storage}->_run_crud_pinned('select', $self->{pg}, @_) } | ||||||||||||||||||||
|
Subroutine
select_async: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||
| 42 | 1 | ▶ | sub select_single_async { my $self = shift; $self->{storage}->_run_crud_pinned('select_single', $self->{pg}, @_) } | ||||||||||||||||||||
|
Subroutine
select_single_async: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||
| 43 | 2 | ▶ | sub insert_async { my $self = shift; $self->{storage}->_run_crud_pinned('insert', $self->{pg}, @_) } | ||||||||||||||||||||
|
Subroutine
insert_async: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||
| 44 | 1 | ▶ | sub update_async { my $self = shift; $self->{storage}->_run_crud_pinned('update', $self->{pg}, @_) } | ||||||||||||||||||||
|
Subroutine
update_async: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||
| 45 | 1 | ▶ | sub delete_async { my $self = shift; $self->{storage}->_run_crud_pinned('delete', $self->{pg}, @_) } | ||||||||||||||||||||
|
Subroutine
delete_async: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||
| 46 | 0 | ▶ | sub select { my $self = shift; $self->select_async(@_)->get } | ||||||||||||||||||||
|
Subroutine
select: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||
| 47 | 0 | ▶ | sub select_single { my $self = shift; $self->select_single_async(@_)->get } | ||||||||||||||||||||
|
Subroutine
select_single: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||
| 48 | 1 | ▶ | sub insert { my $self = shift; $self->insert_async(@_)->get } | ||||||||||||||||||||
|
Subroutine
insert: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||
| 49 | 0 | ▶ | sub update { my $self = shift; $self->update_async(@_)->get } | ||||||||||||||||||||
|
Subroutine
update: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||
| 50 | 0 | ▶ | sub delete { my $self = shift; $self->delete_async(@_)->get } | ||||||||||||||||||||
|
Subroutine
delete: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||
| 51 | 0 | ▶ | sub sql_maker { my $self = shift; $self->{storage}->sql_maker(@_) } | ||||||||||||||||||||
|
Subroutine
sql_maker: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||
| 52 | 0 | ▶ | sub debug { my $self = shift; $self->{storage}->debug(@_) } | ||||||||||||||||||||
|
Subroutine
debug: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||
| 53 | |||||||||||||||||||||||
| 54 | 5 | 1; | |||||||||||||||||||||
| 55 | |||||||||||||||||||||||
| 56 | __END__ | ||||||||||||||||||||||
| 57 | |||||||||||||||||||||||
| 58 | =pod | ||||||||||||||||||||||
| 59 | |||||||||||||||||||||||
| 60 | =encoding UTF-8 | ||||||||||||||||||||||
| 61 | |||||||||||||||||||||||
| 62 | =head1 NAME | ||||||||||||||||||||||
| 63 | |||||||||||||||||||||||
| 64 | DBIO::PostgreSQL::Async::TransactionContext - Pinned connection context for an async PostgreSQL transaction | ||||||||||||||||||||||
| 65 | |||||||||||||||||||||||
| 66 | =head1 VERSION | ||||||||||||||||||||||
| 67 | |||||||||||||||||||||||
| 68 | version 0.900000 | ||||||||||||||||||||||
| 69 | |||||||||||||||||||||||
| 70 | =head1 ATTRIBUTES | ||||||||||||||||||||||
| 71 | |||||||||||||||||||||||
| 72 | =head2 storage | ||||||||||||||||||||||
| 73 | |||||||||||||||||||||||
| 74 | The parent L<DBIO::PostgreSQL::Async::Storage> instance. | ||||||||||||||||||||||
| 75 | |||||||||||||||||||||||
| 76 | =head2 pg | ||||||||||||||||||||||
| 77 | |||||||||||||||||||||||
| 78 | The pinned L<EV::Pg> connection handle for the duration of this transaction. | ||||||||||||||||||||||
| 79 | |||||||||||||||||||||||
| 80 | =head2 pool | ||||||||||||||||||||||
| 81 | |||||||||||||||||||||||
| 82 | Shortcut to C<< $self->storage->pool >>. | ||||||||||||||||||||||
| 83 | |||||||||||||||||||||||
| 84 | =head2 in_txn | ||||||||||||||||||||||
| 85 | |||||||||||||||||||||||
| 86 | Always true — indicates we are inside a transaction. | ||||||||||||||||||||||
| 87 | |||||||||||||||||||||||
| 88 | =head1 METHODS | ||||||||||||||||||||||
| 89 | |||||||||||||||||||||||
| 90 | =head2 _query_async | ||||||||||||||||||||||
| 91 | |||||||||||||||||||||||
| 92 | Executes a query on the pinned transaction connection without releasing | ||||||||||||||||||||||
| 93 | it back to the pool. Uses L<DBIO::PostgreSQL::Async::Storage/_query_async_pinned>. | ||||||||||||||||||||||
| 94 | |||||||||||||||||||||||
| 95 | =head1 AUTHOR | ||||||||||||||||||||||
| 96 | |||||||||||||||||||||||
| 97 | DBIO Authors | ||||||||||||||||||||||
| 98 | |||||||||||||||||||||||
| 99 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||
| 100 | |||||||||||||||||||||||
| 101 | Copyright (C) 2026 DBIO Authors | ||||||||||||||||||||||
| 102 | |||||||||||||||||||||||
| 103 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||
| 104 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||
| 105 | |||||||||||||||||||||||
| 106 | =cut | ||||||||||||||||||||||