DBIO-MySQL-Async

 view release on metacpan or  search on metacpan

lib/DBIO/MySQL/Async/Storage.pm  view on Meta::CPAN

  return $self->_run_crud('select_single', undef, @_);
}


sub insert_async {
  my $self = shift;
  return $self->_run_crud('insert', undef, @_);
}


sub update_async {
  my $self = shift;
  return $self->_run_crud('update', undef, @_);
}


sub delete_async {
  my $self = shift;
  return $self->_run_crud('delete', undef, @_);
}

lib/DBIO/MySQL/Async/Storage.pm  view on Meta::CPAN

sub select_single {
  my $self = shift;
  return $self->select_single_async(@_)->get;
}

sub insert {
  my $self = shift;
  return $self->insert_async(@_)->get;
}

sub update {
  my $self = shift;
  return $self->update_async(@_)->get;
}

sub delete {
  my $self = shift;
  return $self->delete_async(@_)->get;
}

sub txn_do {

lib/DBIO/MySQL/Async/TransactionContext.pm  view on Meta::CPAN

# BEGIN/COMMIT ran on, not a fresh pooled one. Each CRUD method routes
# through the storage's shared CRUD builder with the pinned connection
# (txn_mdb), so SQL generation (insert + LAST_INSERT_ID, select_single
# first-row) is not duplicated. Forwarding to $storage->select_async etc.
# would acquire a separate pool connection and run the query OUTSIDE the
# transaction.

sub select_async        { my $s = shift; $s->{storage}->_run_crud_pinned('select',        $s->{mdb}, @_) }
sub select_single_async { my $s = shift; $s->{storage}->_run_crud_pinned('select_single', $s->{mdb}, @_) }
sub insert_async        { my $s = shift; $s->{storage}->_run_crud_pinned('insert',        $s->{mdb}, @_) }
sub update_async        { my $s = shift; $s->{storage}->_run_crud_pinned('update',        $s->{mdb}, @_) }
sub delete_async        { my $s = shift; $s->{storage}->_run_crud_pinned('delete',        $s->{mdb}, @_) }
sub select              { my $s = shift; $s->select_async(@_)->get        }
sub select_single       { my $s = shift; $s->select_single_async(@_)->get }
sub insert              { my $s = shift; $s->insert_async(@_)->get        }
sub update              { my $s = shift; $s->update_async(@_)->get        }
sub delete              { my $s = shift; $s->delete_async(@_)->get        }
sub sql_maker           { my $s = shift; $s->{storage}->sql_maker(@_)           }
sub debug               { my $s = shift; $s->{storage}->debug(@_)               }
sub pipeline            { my $s = shift; $s->{storage}->pipeline(@_)            }
sub txn_do_async        { my $s = shift; $s->{storage}->txn_do_async(@_)        }

1;

__END__

t/transaction-context.t  view on Meta::CPAN

  # Records the op and the connection it was pinned to.
  sub _run_crud_pinned {
    my ($self, $op, $mdb, @args) = @_;
    push @{ $self->{_crud} //= [] }, { op => $op, mdb => $mdb };
    return Future->done([]);
  }
  # These should NOT be reached by the context anymore — if they are, the
  # query is escaping the transaction onto a fresh pool connection.
  sub select_async        { die 'select_async on storage MUST NOT be called from txn context' }
  sub select_single_async { die 'select_single_async on storage MUST NOT be called from txn context' }
  sub update_async        { die 'update_async on storage MUST NOT be called from txn context' }
  sub delete_async        { die 'delete_async on storage MUST NOT be called from txn context' }
  sub insert_async        { die 'insert_async on storage MUST NOT be called from txn context' }
  sub pipeline        { push @{$_[0]->{_queries} //= []}, 'pipeline'; Future->done([]) }
  sub txn_do_async    { push @{$_[0]->{_queries} //= []}, 'txn_do_async'; Future->done([]) }
  sub select          { push @{$_[0]->{_queries} //= []}, 'select'; 'SELECT_RESULT' }
  sub select_single   { push @{$_[0]->{_queries} //= []}, 'select_single'; 'SELECT_SINGLE_RESULT' }
  sub insert          { push @{$_[0]->{_queries} //= []}, 'insert'; 'INSERT_RESULT' }
  sub update          { push @{$_[0]->{_queries} //= []}, 'update'; 'UPDATE_RESULT' }
  sub delete          { push @{$_[0]->{_queries} //= []}, 'delete'; 'DELETE_RESULT' }
}
{
  package MockPoolMySQL;
  sub new { bless {}, $_[0] }
  sub release { }
}
{
  package MockConnMySQL;
  sub new { bless {}, $_[0] }



( run in 1.012 second using v1.01-cache-2.11-cpan-600a1bdf6e4 )