DBIx-Async

 view release on metacpan or  search on metacpan

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

use Future;
use Module::Load qw();

use Variable::Disposition qw(retain_future);

use DBIx::Async::Handle;

# temporary pending next release of curry
our $_curry_weak = sub {
	my ($invocant, $code) = splice @_, 0, 2;
	Scalar::Util::weaken($invocant) if Scalar::Util::blessed($invocant);
	my @args = @_;
	sub {
		return unless $invocant;
		$invocant->$code(@args => @_)
	}
};

=head2 connect

Constuctor. Sets up our instance with parameters that will be used when we attempt to

t/sqlite3.t  view on Meta::CPAN

use strict;
use warnings;

use Test::More;
use Test::Fatal;
use curry;
use Scalar::Util qw(weaken);
use DBIx::Async;
use Future::Utils qw(fmap_void repeat);
use IO::Async::Loop;

plan skip_all => 'sqlite3 not found' unless eval { require DBD::SQLite; };

my $loop = IO::Async::Loop->new;
my $dbh;
is(exception {
	$dbh = DBIx::Async->connect(

t/sqlite3.t  view on Meta::CPAN

}, undef, '... but no exception for a valid table');

{
	my $sth_copy;
	{ # Add some data
		isa_ok(my $sth = $dbh->prepare(q{insert into our_table (content) values (?)}), 'DBIx::Async::Handle');
		(fmap_void {
			$sth->execute(shift)
		} foreach => [qw(first second third)])->get;
		is(exception { $sth->finish->get }, undef, 'can finish the statement without error');
		weaken($sth_copy = $sth);
	}
	is($sth_copy, undef, 'statement handle has gone away');
}

{ # Add more data in a transaction, then throw it away
	$dbh->begin_work->get;
	isa_ok(my $sth = $dbh->prepare(q{insert into our_table (content) values (?)}), 'DBIx::Async::Handle');
	(fmap_void {
		$sth->execute(shift)
	} foreach => [qw(fourth fifth)])->get;



( run in 0.419 second using v1.01-cache-2.11-cpan-65fba6d93b7 )