Database-Async
view release on metacpan or search on metacpan
lib/Database/Async.pm view on Meta::CPAN
193194195196197198199200201202203204205206207208209210211212=head2 transaction
Resolves to a L<Future> which will yield a L<Database::Async::Transaction>
instance once ready.
=cut
async
sub
transaction {
my
(
$self
,
@args
) =
@_
;
Scalar::Util::weaken(
$self
->{transactions}[@{
$self
->{transactions}}] =
my
$txn
= Database::Async::Transaction->new(
database
=>
$self
,
@args
)
);
await
$txn
->begin;
return
$txn
;
}
lib/Database/Async/Engine.pm view on Meta::CPAN
3738394041424344454647484950515253545556sub
uri {
shift
->{uri} }
sub
db {
shift
->{db} }
sub
configure {
my
(
$self
,
%args
) =
@_
;
for
(
qw(uri)
) {
$self
->{
$_
} = URI->new(
''
.
delete
(
$args
{
$_
}))
if
exists
$args
{
$_
};
}
for
(
qw(db)
) {
Scalar::Util::weaken(
$self
->{
$_
} =
delete
$args
{
$_
})
if
exists
$args
{
$_
};
}
$self
->
next
::method(
%args
);
}
1;
=head1 AUTHOR
Tom Molesworth C<< <TEAM@cpan.org> >>
lib/Database/Async/Query.pm view on Meta::CPAN
185186187188189190191192193194195196197198199200201202203204205use
overload
'""'
=>
sub
{
my
(
$self
) =
@_
;
sprintf
'%s[%s]'
,
ref
(
$self
),
$self
->sql },
bool
=>
sub
{ 1 },
fallback
=> 1;
sub
new {
my
(
$class
,
%args
) =
@_
;
Scalar::Util::weaken(
$args
{db});
bless
\
%args
,
$class
;
}
=head2 in
This is a L<Ryu::Sink> used for queries which stream data to the server.
It's buffered internally.
=cut
lib/Database/Async/Transaction.pm view on Meta::CPAN
262728293031323334353637383940414243444546=head2 new
Instantiates the transaction. This is not intended to be called directly;
that's normally handled by L<Database::Async> itself.
=cut
sub
new {
my
(
$class
,
%args
) =
@_
;
Scalar::Util::weaken(
$args
{database} ||
die
'expected database parameter'
);
$args
{
open
} //= 0;
bless
\
%args
,
$class
}
sub
database {
shift
->{database} }
sub
begin {
my
(
$self
) =
@_
;
my
$query
= Database::Async::Query->new(
db
=>
$self
->database,
192021222324252627282930313233343536373839);
isa_ok(
my
$pool
=
$db
->pool,
'Database::Async::Pool'
);
is(
$pool
->min, 0,
'min value passed through from constructor'
);
is(
$pool
->max, 5,
'max value passed through from constructor'
);
my
$engine
= Database::Async::Engine::Empty->new;
is(
$pool
->count, 0,
'no engines in pool yet'
);
$pool
->register_engine(
$engine
);
is(
$pool
->count, 1,
'now have one engine in pool'
);
$pool
->queue_ready_engine(
$engine
);
Scalar::Util::weaken(
$engine
);
is(exception {
isa_ok(
my
$f
=
$pool
->next_engine,
'Future'
);
ok(
$f
->is_ready,
'the engine is available immediately'
);
is(
$f
->get,
$engine
,
'requested engine matches ready one'
);
my
$requested
= 0;
local
$pool
->{request_engine} = async
sub
{
++
$requested
;
};
isa_ok(
my
$next
=
$pool
->next_engine,
'Future'
);
is(
$requested
, 1,
'asked for one engine'
);
( run in 0.370 second using v1.01-cache-2.11-cpan-e5176c747c2 )