File Coverage

blib/lib/Database/Async/DB.pm
Criterion Covered Total %
statement 15 32 46.8
branch n/a
condition n/a
subroutine 5 12 41.6
pod 2 7 28.5
total 22 51 43.1


line stmt bran cond sub pod time code
1             package Database::Async::DB;
2              
3 2     2   823 use strict;
  2         4  
  2         57  
4 2     2   10 use warnings;
  2         3  
  2         75  
5              
6             our $VERSION = '0.016'; # VERSION
7              
8 2     2   721 use Future;
  2         14859  
  2         76  
9              
10 2     2   814 use Database::Async::StatementHandle;
  2         6  
  2         65  
11              
12 2     2   958 use Log::Any qw($log);
  2         17161  
  2         10  
13              
14             our @METHODS = qw(
15             do
16             prepare
17             insert
18             query
19             );
20              
21 0     0 0   sub db { shift->{db} }
22              
23             =head2 do
24              
25             Executes the given SQL with optional bind parameters.
26              
27             =cut
28              
29             sub do : method {
30 0     0 1   my ($self, $sql, %args) = @_;
31 0           Future->done
32             }
33              
34             =head2 prepare
35              
36             Prepares a L.
37              
38             =cut
39              
40             sub prepare {
41 0     0 1   my ($self, $sql) = @_;
42 0           Future->done(
43             Database::Async::StatementHandle->new
44             )
45             }
46              
47             sub quote_table_name {
48 0     0 0   my ($self, $name) = @_;
49 0           $name =~ s/"/""/g;
50 0           '"' . $name . '"'
51             }
52              
53             sub quote_field_name {
54 0     0 0   my ($self, $name) = @_;
55 0           $name =~ s/"/""/g;
56 0           '"' . $name . '"'
57             }
58              
59             sub insert {
60 0     0 0   my ($self, $table, $data) = @_;
61             $self->query(
62             'insert into '
63             . $self->quote_table_name(
64             $table
65             )
66             . ' ('
67 0           . join(',', map { $self->quote_field_name($_) } keys %$data)
  0            
68             . ') values ('
69             . join(',', ('?') x (keys %$data))
70             . ')',
71             values %$data
72             )
73             }
74              
75             sub query {
76 0     0 0   my ($self, $sql, @bind) = @_;
77 0           $log->tracef('Attempting query %s with %s', $sql, \@bind);
78 0           Database::Async::Query->new(
79             db => $self->db,
80             sql => $sql,
81             bind => \@bind
82             )
83             }
84              
85             1;
86              
87             =head1 AUTHOR
88              
89             Tom Molesworth C<< >>
90              
91             =head1 LICENSE
92              
93             Copyright Tom Molesworth 2011-2021. Licensed under the same terms as Perl itself.
94