... | ... |
@@ -1,4 +1,6 @@ |
1 |
-0.2108 |
|
1 |
+0.2110 |
|
2 |
+ - added EXPERIMETNAL aysnc_conf attribute |
|
3 |
+0.2109 |
|
2 | 4 |
- select method can be called even if table name is not specified |
3 | 5 |
0.2108 |
4 | 6 |
- added async database access support using AnyEvent |
... | ... |
@@ -1,7 +1,7 @@ |
1 | 1 |
package DBIx::Custom; |
2 | 2 |
use Object::Simple -base; |
3 | 3 |
|
4 |
-our $VERSION = '0.2109'; |
|
4 |
+our $VERSION = '0.2110'; |
|
5 | 5 |
use 5.008001; |
6 | 6 |
|
7 | 7 |
use Carp 'croak'; |
... | ... |
@@ -22,6 +22,7 @@ use Scalar::Util qw/weaken/; |
22 | 22 |
|
23 | 23 |
has [qw/connector dsn password quote user exclude_table user_table_info |
24 | 24 |
user_column_info safety_character/], |
25 |
+ async_conf => sub { {} }, |
|
25 | 26 |
cache => 0, |
26 | 27 |
cache_method => sub { |
27 | 28 |
sub { |
... | ... |
@@ -346,6 +347,7 @@ sub execute { |
346 | 347 |
my %opt = @_; |
347 | 348 |
|
348 | 349 |
# Async query |
350 |
+ $opt{prepare_attr} = $self->async_conf->{prepare_attr} if $opt{async}; |
|
349 | 351 |
if ($opt{async} && !$self->{_new_connection}) { |
350 | 352 |
my $dsn = $self->dsn; |
351 | 353 |
croak qq/Data source must be specified when "async" option is used/ |
... | ... |
@@ -612,7 +614,7 @@ sub execute { |
612 | 614 |
my $watcher; |
613 | 615 |
weaken $self; |
614 | 616 |
$watcher = AnyEvent->io( |
615 |
- fh => $self->{dbh}->mysql_fd, |
|
617 |
+ fh => $self->async_conf->{fh}->($self), |
|
616 | 618 |
poll => 'r', |
617 | 619 |
cb => sub { |
618 | 620 |
$cb->($self, $result); |
... | ... |
@@ -2183,6 +2185,22 @@ L<DBIx::Custom::Order> |
2183 | 2185 |
|
2184 | 2186 |
=head1 ATTRIBUTES |
2185 | 2187 |
|
2188 |
+=head2 C<async_conf> EXPERIMENTAL |
|
2189 |
+ |
|
2190 |
+ my $async_conf = $dbi->async_conf; |
|
2191 |
+ $dbi = $dbi->async_conf($conf); |
|
2192 |
+ |
|
2193 |
+Setting when C<async> option is used. |
|
2194 |
+ |
|
2195 |
+ # MySQL |
|
2196 |
+ $dbi->async_conf({ |
|
2197 |
+ prepare_attr => {async => 1}, |
|
2198 |
+ fh => sub { shift->dbh->mysql_fd } |
|
2199 |
+ }) |
|
2200 |
+ |
|
2201 |
+C<prepare_attr> is DBI's C<prepare> method second argument, |
|
2202 |
+C<fh> is callback that return file handle to watch. |
|
2203 |
+ |
|
2186 | 2204 |
=head2 C<connector> |
2187 | 2205 |
|
2188 | 2206 |
my $connector = $dbi->connector; |
... | ... |
@@ -67,8 +67,13 @@ my $timer = AnyEvent->timer( |
67 | 67 |
|
68 | 68 |
my $count = 0; |
69 | 69 |
|
70 |
+$dbi->async_conf({ |
|
71 |
+ prepare_attr => {async => 1}, |
|
72 |
+ fh => sub { shift->dbh->mysql_fd } |
|
73 |
+}); |
|
74 |
+ |
|
70 | 75 |
$dbi->execute('SELECT SLEEP(1), 3', undef, |
71 |
- prepare_attr => {async => 1}, select => 1, |
|
76 |
+ select => 1, |
|
72 | 77 |
async => sub { |
73 | 78 |
my ($dbi, $result) = @_; |
74 | 79 |
my $row = $result->fetch_one; |
... | ... |
@@ -77,12 +82,12 @@ $dbi->execute('SELECT SLEEP(1), 3', undef, |
77 | 82 |
} |
78 | 83 |
); |
79 | 84 |
|
80 |
-$dbi->select('key1', table => 'table1', prepare_attr => {async => 1}, |
|
85 |
+$dbi->select('key1', table => 'table1', |
|
81 | 86 |
async => sub { |
82 | 87 |
my ($dbi, $result) = @_; |
83 | 88 |
my $row = $result->fetch_one; |
84 | 89 |
is($row->[0], 1, 'after1'); |
85 |
- $dbi->select('key1', table => 'table1', prepare_attr => {async => 1}, |
|
90 |
+ $dbi->select('key1', table => 'table1', |
|
86 | 91 |
async => sub { |
87 | 92 |
my ($dbi, $result) = @_; |
88 | 93 |
my $row = $result->fetch_one; |