Database-Async

 view release on metacpan or  search on metacpan

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

        my $exception = $@;
        try {
            await $txn->rollback;
        } catch {
            $log->warnf("exception %s in rollback", $@);
        }
        die $exception;
    }
}

=head1 METHODS - Internal

You're welcome to call these, but they're mostly intended
for internal usage, and the API B<may> change in future versions.

=cut

=head2 uri

Returns the configured L<URI> for populating database instances.

=cut

sub uri { shift->{uri} }

=head2 pool

Returns the L<Database::Async::Pool> instance.

=cut

sub pool {
    my ($self) = @_;
    $self->{pool} ||= Database::Async::Pool->new(
        $self->pool_args
    );
}

=head2 pool_args

Returns a list of standard pool constructor arguments.

=cut

sub pool_args {
    my ($self) = @_;
    return (
        request_engine => $self->curry::weak::request_engine,
        uri            => $self->uri,
    );
}

=head2 configure

Applies configuration, see L<IO::Async::Notifier> for details.

Supports the following named parameters:

=over 4

=item * C<uri> - the endpoint to use when connecting a new engine instance

=item * C<engine> - the parameters to pass when instantiating a new L<Database::Async::Engine>

=item * C<pool> - parameters for setting up the pool, or a L<Database::Async::Pool> instance

=item * C<encoding> - default encoding to apply to parameters, queries and results, defaults to C<binary>

=back

=cut

my %encoding_map = (
    'utf8'    => 'UTF-8',
    'utf-8'   => 'UTF-8',
    'UTF8'    => 'UTF-8',
    'unicode' => 'UTF-8',
);

sub configure {
    my ($self, %args) = @_;

    if(my $encoding = delete $args{encoding}) {
        $self->{encoding} = $encoding_map{$encoding} // $encoding;
    }

    if(my $uri = delete $args{uri}) {
        # This could be any type of object. We make
        # the assumption here that it safely serialises
        # to a standard URI. Some of the database
        # engines provide such a standard (e.g. PostgreSQL).
        # Others may not...
        $self->{uri} = URI->new("$uri");
    }
    if(exists $args{engine}) {
        $self->{engine_parameters} = delete $args{engine};
    }
    if(exists $args{type}) {
        $self->{type} = delete $args{type};
    }
    if(my $pool = delete $args{pool}) {
        if(blessed $pool) {
            $self->{pool} = $pool;
        } else {
            $self->{pool} = Database::Async::Pool->new(
                $self->pool_args,
                %$pool,
            );
        }
    }
    $self->next::method(%args);
}

sub encoding { shift->{encoding} }

=head2 ryu

A L<Ryu::Async> instance, used for requesting sources, sinks and timers.

=cut



( run in 1.265 second using v1.01-cache-2.11-cpan-39bf76dae61 )