Database-Async

 view release on metacpan or  search on metacpan

lib/Database/Async.pm  view on Meta::CPAN

193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
=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

37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
sub 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

185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
use Log::Any qw($log);
 
    '""' => 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

26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
=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,

t/pool.t  view on Meta::CPAN

19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
);
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 )