| 1 | package Database::Async::DB; | ||
| 2 | |||
| 3 | 6 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 6 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | 6 | our $VERSION = '0.019'; # VERSION | |
| 7 | |||
| 8 | 6 | ▶ | use Future; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | |||
| 10 | 6 | ▶ | use Database::Async::StatementHandle; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | |||
| 12 | 6 | ▶ | use Log::Any qw($log); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 13 | |||
| 14 | 6 | our @METHODS = qw( | |
| 15 | do | ||
| 16 | prepare | ||
| 17 | insert | ||
| 18 | query | ||
| 19 | ); | ||
| 20 | |||
| 21 | 0 | ▶ | sub db { shift->{db} } |
|
Subroutine
db: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 22 | |||
| 23 | =head2 do | ||
| 24 | |||
| 25 | Executes the given SQL with optional bind parameters. | ||
| 26 | |||
| 27 | =cut | ||
| 28 | |||
| 29 | 0 | ▶ | sub do : method { |
|
Subroutine
do: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 30 | 0 | my ($self, $sql, %args) = @_; | |
| 31 | 0 | Future->done | |
| 32 | } | ||
| 33 | |||
| 34 | =head2 prepare | ||
| 35 | |||
| 36 | Prepares a L<Database::Async::StatementHandle>. | ||
| 37 | |||
| 38 | =cut | ||
| 39 | |||
| 40 | 0 | ▶ | sub prepare { |
|
Subroutine
prepare: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 41 | 0 | my ($self, $sql) = @_; | |
| 42 | 0 | Future->done( | |
| 43 | Database::Async::StatementHandle->new | ||
| 44 | ) | ||
| 45 | } | ||
| 46 | |||
| 47 | 0 | ▶ | sub quote_table_name { |
|
Subroutine
quote_table_name: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 48 | 0 | my ($self, $name) = @_; | |
| 49 | 0 | $name =~ s/"/""/g; | |
| 50 | 0 | '"' . $name . '"' | |
| 51 | } | ||
| 52 | |||
| 53 | 0 | ▶ | sub quote_field_name { |
|
Subroutine
quote_field_name: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 54 | 0 | my ($self, $name) = @_; | |
| 55 | 0 | $name =~ s/"/""/g; | |
| 56 | 0 | '"' . $name . '"' | |
| 57 | } | ||
| 58 | |||
| 59 | 0 | ▶ | sub insert { |
|
Subroutine
insert: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 60 | 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) | |
| 68 | . ') values (' | ||
| 69 | . join(',', ('?') x (keys %$data)) | ||
| 70 | . ')', | ||
| 71 | values %$data | ||
| 72 | ) | ||
| 73 | } | ||
| 74 | |||
| 75 | 0 | ▶ | sub query { |
|
Subroutine
query: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 76 | 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 | 6 | 1; | |
| 86 | |||
| 87 | =head1 AUTHOR | ||
| 88 | |||
| 89 | Tom Molesworth C<< <TEAM@cpan.org> >> | ||
| 90 | |||
| 91 | =head1 LICENSE | ||
| 92 | |||
| 93 | Copyright Tom Molesworth 2011-2023. Licensed under the same terms as Perl itself. | ||
| 94 | |||