line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DBIx::NoSQL::Storage; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:YANICK'; |
3
|
|
|
|
|
|
|
$DBIx::NoSQL::Storage::VERSION = '0.0021'; |
4
|
8
|
|
|
8
|
|
32
|
use Moose; |
|
8
|
|
|
|
|
11
|
|
|
8
|
|
|
|
|
78
|
|
5
|
8
|
|
|
8
|
|
38254
|
use Carp; |
|
8
|
|
|
|
|
13
|
|
|
8
|
|
|
|
|
4570
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
has store => qw/ is ro required 1 weak_ref 1 /; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
has statement_caching => qw/ is rw isa Bool default 0 /; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has foreign_storage => qw/ is ro lazy_build 1 weak_ref 1 /; |
12
|
|
|
|
|
|
|
sub _build_foreign_storage { |
13
|
9
|
|
|
9
|
|
14
|
my $self = shift; |
14
|
9
|
|
|
|
|
201
|
return $self->store->schema->storage; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub do { |
18
|
51
|
|
|
51
|
0
|
86
|
my $self = shift; |
19
|
51
|
|
|
|
|
68
|
my $statement = shift; |
20
|
51
|
|
|
|
|
76
|
my @bind = @_; |
21
|
|
|
|
|
|
|
|
22
|
51
|
|
|
|
|
59
|
my $attributes; |
23
|
51
|
50
|
33
|
|
|
164
|
$attributes = shift @bind if @bind && ref $bind[0] eq 'HASH'; |
24
|
|
|
|
|
|
|
|
25
|
51
|
|
|
|
|
135
|
$self->_query_start( $statement => @bind ); |
26
|
|
|
|
|
|
|
$self->foreign_storage->dbh_do( sub { |
27
|
51
|
|
|
51
|
|
9678
|
$_[1]->do( $statement, $attributes, @bind ); |
28
|
51
|
|
|
|
|
1161
|
} ); |
29
|
50
|
|
|
|
|
388464261
|
$self->_query_end( $statement => @bind ); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub retrying_do { |
33
|
7
|
|
|
7
|
0
|
14
|
my $self = shift; |
34
|
7
|
|
|
|
|
11
|
my $code = shift; |
35
|
|
|
|
|
|
|
|
36
|
7
|
|
|
|
|
474
|
return $self->foreign_storage->dbh_do( $code, @_ ); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub select { |
40
|
47
|
|
|
47
|
0
|
74
|
my $self = shift; |
41
|
47
|
|
|
|
|
65
|
my $statement = shift; |
42
|
47
|
|
|
|
|
137
|
my $attributes = shift; |
43
|
47
|
|
|
|
|
56
|
my $bind = shift; |
44
|
|
|
|
|
|
|
|
45
|
47
|
|
|
|
|
134
|
$self->_query_start( $statement => @$bind ); |
46
|
|
|
|
|
|
|
|
47
|
47
|
|
|
|
|
2666
|
my $foreign = $self->foreign_storage; |
48
|
|
|
|
|
|
|
my $sth = $foreign->dbh_do( sub { |
49
|
47
|
|
|
47
|
|
212961
|
my $dbh = $_[1]; |
50
|
47
|
50
|
0
|
|
|
1465
|
my $sth = $self->statement_caching ? |
|
|
|
50
|
|
|
|
|
51
|
|
|
|
|
|
|
$dbh->prepare_cached( $statement, $attributes || {}, 3 ) : |
52
|
|
|
|
|
|
|
$dbh->prepare( $statement, $attributes || {} ) |
53
|
|
|
|
|
|
|
; |
54
|
47
|
50
|
|
|
|
9470
|
croak $dbh->errstr unless $sth; |
55
|
47
|
|
|
|
|
165
|
return $sth; |
56
|
47
|
|
|
|
|
391
|
} ); |
57
|
|
|
|
|
|
|
|
58
|
47
|
|
|
|
|
6564
|
my $rv = $sth->execute( @$bind ); |
59
|
47
|
50
|
0
|
|
|
146
|
croak $sth->errstr || $sth->err || "Unknown error: \$sth->execute return false without setting an error flag" unless $rv; |
60
|
|
|
|
|
|
|
|
61
|
47
|
|
|
|
|
168
|
$self->_query_end( $statement, @$bind ); |
62
|
|
|
|
|
|
|
|
63
|
47
|
|
|
|
|
998
|
return $sth; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub cursor { |
67
|
46
|
|
|
46
|
0
|
72
|
my $self = shift; |
68
|
46
|
|
|
|
|
74
|
my $statement = shift; |
69
|
46
|
|
|
|
|
57
|
my $attributes; |
70
|
46
|
50
|
|
|
|
151
|
$attributes = shift if ref $_[0] eq 'HASH'; |
71
|
46
|
|
|
|
|
62
|
my $bind = shift; |
72
|
|
|
|
|
|
|
|
73
|
46
|
|
|
|
|
317
|
return DBIx::NoSQL::Storage::Cursor->new( storage => $self, statement => $statement, attributes => $attributes, bind => $bind ); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub _query_start { |
77
|
98
|
|
|
98
|
|
121
|
my $self = shift; |
78
|
98
|
50
|
|
|
|
2329
|
if ( $self->foreign_storage->debug ) { |
79
|
0
|
|
|
|
|
0
|
$self->foreign_storage->debugobj->query_start( @_ ); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub _query_end { |
84
|
97
|
|
|
97
|
|
196
|
my $self = shift; |
85
|
97
|
50
|
|
|
|
4278
|
if ( $self->foreign_storage->debug ) { |
86
|
0
|
|
|
|
|
0
|
$self->foreign_storage->debugobj->query_end( @_ ); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub table_exists { |
91
|
32
|
|
|
32
|
0
|
52
|
my $self = shift; |
92
|
32
|
|
|
|
|
49
|
my $table_name = shift; |
93
|
|
|
|
|
|
|
|
94
|
32
|
|
|
|
|
47
|
my $statement = <<_END_; |
95
|
|
|
|
|
|
|
SELECT COUNT(*) FROM sqlite_master WHERE type = 'table' AND name = ? |
96
|
|
|
|
|
|
|
_END_ |
97
|
32
|
|
|
|
|
88
|
my @bind = ( $table_name ); |
98
|
|
|
|
|
|
|
|
99
|
32
|
|
|
|
|
115
|
my $cursor = $self->cursor( $statement, \@bind ); |
100
|
32
|
|
|
|
|
34235
|
my $result = $cursor->next; |
101
|
32
|
100
|
|
|
|
252
|
return $result->[0] ? 1 : 0; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
package DBIx::NoSQL::Storage::Cursor; |
105
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:YANICK'; |
106
|
|
|
|
|
|
|
$DBIx::NoSQL::Storage::Cursor::VERSION = '0.0021'; |
107
|
8
|
|
|
8
|
|
42
|
use Moose; |
|
8
|
|
|
|
|
10
|
|
|
8
|
|
|
|
|
35
|
|
108
|
8
|
|
|
8
|
|
33580
|
use Try::Tiny; |
|
8
|
|
|
|
|
12
|
|
|
8
|
|
|
|
|
3094
|
|
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
has storage => qw/ is ro required 1 /; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
has statement => qw/ is ro required 1 /; |
113
|
|
|
|
|
|
|
has attributes => qw/ is ro /; |
114
|
|
|
|
|
|
|
has bind => qw/ is ro required 1 isa ArrayRef /; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
has sth => qw/ is rw /; |
117
|
|
|
|
|
|
|
has finished => qw/ is rw isa Bool default 0 /; |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub _select { |
120
|
47
|
|
|
47
|
|
70
|
my $self = shift; |
121
|
47
|
|
|
|
|
1204
|
return $self->storage->select( $self->statement, $self->attributes, $self->bind ); |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub next { |
125
|
41
|
|
|
41
|
0
|
66
|
my $self = shift; |
126
|
|
|
|
|
|
|
|
127
|
41
|
50
|
|
|
|
1017
|
return if $self->finished; |
128
|
|
|
|
|
|
|
|
129
|
41
|
100
|
|
|
|
961
|
unless ( $self->sth ) { |
130
|
40
|
|
|
|
|
110
|
$self->sth( $self->_select ); |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
41
|
100
|
|
|
|
892
|
my $row = $self->sth->fetchrow_arrayref or do { |
134
|
1
|
|
|
|
|
22
|
$self->sth( undef ); |
135
|
1
|
|
|
|
|
22
|
$self->finished( 0 ); |
136
|
|
|
|
|
|
|
}; |
137
|
|
|
|
|
|
|
|
138
|
41
|
|
100
|
|
|
150
|
return $row || []; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
sub all { |
142
|
7
|
|
|
7
|
0
|
15
|
my $self = shift; |
143
|
|
|
|
|
|
|
|
144
|
7
|
0
|
33
|
|
|
195
|
$self->sth->finish if $self->sth && $self->sth->{Active}; |
145
|
7
|
|
|
|
|
174
|
$self->sth( undef ); |
146
|
7
|
|
|
|
|
10
|
my $sth; |
147
|
|
|
|
|
|
|
$self->storage->retrying_do( sub { |
148
|
7
|
|
|
7
|
|
1888
|
$sth = $self->_select; |
149
|
7
|
|
|
|
|
186
|
} ); |
150
|
7
|
|
|
|
|
744
|
my $all = $sth->fetchall_arrayref; |
151
|
7
|
50
|
|
|
|
27
|
return [] unless $all; |
152
|
7
|
|
|
|
|
114
|
return $all; |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
sub reset { |
156
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
157
|
|
|
|
|
|
|
|
158
|
0
|
0
|
0
|
0
|
|
|
try { $self->sth->finish } if $self->sth && $self->sth->{Active}; |
|
0
|
|
|
|
|
|
|
159
|
0
|
|
|
|
|
|
$self->_soft_reset; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub _soft_reset { |
163
|
0
|
|
|
0
|
|
|
my $self = shift; |
164
|
|
|
|
|
|
|
|
165
|
0
|
|
|
|
|
|
$self->sth( undef ); |
166
|
0
|
|
|
|
|
|
$self->finished( 0 ); |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
1; |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
__END__ |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=pod |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=encoding UTF-8 |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head1 NAME |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
DBIx::NoSQL::Storage |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head1 VERSION |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
version 0.0021 |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=head1 AUTHORS |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=over 4 |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=item * |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
Robert Krimen <robertkrimen@gmail.com> |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=item * |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
Yanick Champoux <yanick@cpan.org> |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=back |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
This software is copyright (c) 2017 by Robert Krimen. |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
204
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=cut |