| 1 | package DBIx::QuickDB::Driver::DuckDB; | ||||||||||||||||||||
| 2 | 4 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 4 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | 4 | ▶ | use Scalar::Util qw/reftype/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 4 | ▶ | use DBIx::QuickDB::Util qw/find_bin/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 4 | our $VERSION = '0.000066'; | |||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 4 | ▶ | use parent 'DBIx::QuickDB::Driver'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 4 | ▶ | use DBIx::QuickDB::Util::HashBase qw{-duckdb -started}; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 4 | my ($DUCKDB, $DBDDUCKDB); | |||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 4 | ▶ | BEGIN { | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.1
| |||||||||||||||||||||
| 17 | 4 | local $@; | |||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 4 | $DUCKDB = find_bin('duckdb'); | |||||||||||||||||||
| 20 | 0 | $DBDDUCKDB = eval { require DBD::DuckDB; 'DBD::DuckDB' }; | |||||||||||||||||||
| 21 | } | ||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | 0 | ▶ | sub version_string { | ||||||||||||||||||
|
Subroutine
version_string: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||
| 24 | 0 | my $binary; | |||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | # Go in reverse order assuming the last param hash provided is most important | ||||||||||||||||||||
| 27 | 0 | for my $arg (reverse @_) { | |||||||||||||||||||
| 28 | 0 | ▶ | my $type = reftype($arg) or next; # skip if not a ref | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 29 | 0 | ▶ | next unless $type eq 'HASH'; # We have a hashref, possibly blessed | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | # If we find a launcher we are done looping, we want to use this binary. | ||||||||||||||||||||
| 32 | 0 | ▶ | $binary = $arg->{+DUCKDB} and last; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 33 | } | ||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | # If no args provided one to use we fallback to the default from $PATH | ||||||||||||||||||||
| 36 | 0 | ▶ | $binary ||= $DUCKDB; | ||||||||||||||||||
|
Condition0%0/3
$binary ||= $DUCKDB
MC/DC0%0/2
$binary ||= $DUCKDB
$binary
$DUCKDB
Truth table0%0/3
A ||= B
A= $binaryB= $DUCKDB
| |||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 0 | ▶ | return 'unknown' unless $binary; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | # Call the binary with '--version', capturing and returning the output using backticks. | ||||||||||||||||||||
| 41 | 0 | return `$binary --version`; | |||||||||||||||||||
| 42 | } | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 6 | ▶ | sub _default_paths { return (duckdb => $DUCKDB) } | ||||||||||||||||||
|
Subroutine
_default_paths: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | 6 | ▶ | sub viable { | ||||||||||||||||||
|
Subroutine
viable: called CC=5 SCAR=16.8
Pod
documented
| |||||||||||||||||||||
| 47 | 6 | my $this = shift; | |||||||||||||||||||
| 48 | 6 | my ($spec) = @_; | |||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | 6 | ▶ | my %check = (ref($this) ? %$this : (), $this->_default_paths, %$spec); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 6 | my @bad; | |||||||||||||||||||
| 53 | 6 | ▶ | push @bad => "'DBD::DuckDB' module could not be loaded, needed for connecting" unless $DBDDUCKDB; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 54 | 6 | ▶ | push @bad => "'duckdb' command is missing, needed for loading SQL" unless $check{+DUCKDB}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | 6 | ▶ | return (1, undef) unless @bad; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 57 | 6 | return (0, join "\n" => @bad); | |||||||||||||||||||
| 58 | } | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | 0 | ▶ | sub init { | ||||||||||||||||||
|
Subroutine
init: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||
| 61 | 0 | my $self = shift; | |||||||||||||||||||
| 62 | 0 | $self->SUPER::init(); | |||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 0 | my %defaults = $self->_default_paths; | |||||||||||||||||||
| 65 | 0 | ▶ | $self->{$_} ||= $defaults{$_} for keys %defaults; | ||||||||||||||||||
|
Condition0%0/3
$self->{$_} ||= $defaults{$_}
MC/DC0%0/2
$self->{$_} ||= $defaults{$_}
$self->{$_}
$defaults{$_}
Truth table0%0/3
A ||= B
A= $self->{$_}B= $defaults{$_}
| |||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | 0 | $self->{+STARTED} = 1; | |||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | 0 | return; | |||||||||||||||||||
| 70 | } | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | 0 | ▶ | sub bootstrap { return } | ||||||||||||||||||
|
Subroutine
bootstrap: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 73 | 0 | ▶ | sub start { return } | ||||||||||||||||||
|
Subroutine
start: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 74 | 0 | ▶ | sub stop { return } | ||||||||||||||||||
|
Subroutine
stop: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | 0 | ▶ | sub clone { | ||||||||||||||||||
|
Subroutine
clone: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 77 | 0 | my $self = shift; | |||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | 0 | local $self->{+STARTED} = 0; | |||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | 0 | return $self->SUPER::clone(@_); | |||||||||||||||||||
| 82 | } | ||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | 0 | ▶ | sub connect_string { | ||||||||||||||||||
|
Subroutine
connect_string: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 85 | 0 | my $self = shift; | |||||||||||||||||||
| 86 | 0 | my ($db_name) = @_; | |||||||||||||||||||
| 87 | 0 | ▶ | $db_name = 'quickdb' unless defined $db_name; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | 0 | my $dir = $self->{+DIR}; | |||||||||||||||||||
| 90 | 0 | my $path = "$dir/$db_name"; | |||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | 0 | require DBD::DuckDB; | |||||||||||||||||||
| 93 | 0 | return "dbi:DuckDB:dbname=$path"; | |||||||||||||||||||
| 94 | } | ||||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | 0 | ▶ | sub load_sql { | ||||||||||||||||||
|
Subroutine
load_sql: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 97 | 0 | my $self = shift; | |||||||||||||||||||
| 98 | 0 | my ($db_name, $file) = @_; | |||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | 0 | my $dir = $self->{+DIR}; | |||||||||||||||||||
| 101 | 0 | my $path = "$dir/$db_name"; | |||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | # DBD::DuckDB cannot prepare multiple statements in one do(); the CLI reads | ||||||||||||||||||||
| 104 | # statements from STDIN, so pipe the file through it. | ||||||||||||||||||||
| 105 | 0 | $self->run_command([$self->{+DUCKDB}, $path], {stdin => $file}); | |||||||||||||||||||
| 106 | } | ||||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | 0 | ▶ | sub shell_command { | ||||||||||||||||||
|
Subroutine
shell_command: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 109 | 0 | my $self = shift; | |||||||||||||||||||
| 110 | 0 | my ($db_name) = @_; | |||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | 0 | my $dir = $self->{+DIR}; | |||||||||||||||||||
| 113 | 0 | my $path = "$dir/$db_name"; | |||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | 0 | return ($self->{+DUCKDB}, $path); | |||||||||||||||||||
| 116 | } | ||||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | 4 | 1; | |||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | __END__ | ||||||||||||||||||||