| 1 | package DBIO::DuckDB::Test; | ||||||||||||||
| 2 | # ABSTRACT: DuckDB-specific test utilities for DBIO | ||||||||||||||
| 3 | |||||||||||||||
| 4 | 8 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 8 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | |||||||||||||||
| 7 | 8 | ▶ | use DBIO::Test; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | 8 | ▶ | use DBIO::Test::Schema; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | 8 | ▶ | use Carp; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | |||||||||||||||
| 11 | |||||||||||||||
| 12 | 8 | ▶ | sub import { | ||||||||||||
|
Subroutine
import: called CC=6 SCAR=29.5
| |||||||||||||||
| 13 | 8 | my $self = shift; | |||||||||||||
| 14 | 8 | ▶ | if (@_) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 15 | 0 | my $caller = caller; | |||||||||||||
| 16 | 0 | for my $exp (@_) { | |||||||||||||
| 17 | 0 | ▶ | if ($exp eq ':DiffSQL') { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 18 | 0 | require DBIO::SQLMaker; | |||||||||||||
| 19 | 0 | require SQL::Abstract::Test; | |||||||||||||
| 20 | 0 | for (qw(is_same_sql_bind is_same_sql is_same_bind)) { | |||||||||||||
| 21 | 8 | ▶ | no strict 'refs'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 22 | 0 | *{"${caller}::$_"} = \&{"SQL::Abstract::Test::$_"}; | |||||||||||||
| 23 | } | ||||||||||||||
| 24 | } | ||||||||||||||
| 25 | elsif ($exp eq ':GlobalLock') { | ||||||||||||||
| 26 | # no-op, parallel to DBIO::SQLite::Test | ||||||||||||||
| 27 | } | ||||||||||||||
| 28 | else { | ||||||||||||||
| 29 | 0 | croak "Unknown export $exp requested from $self"; | |||||||||||||
| 30 | } | ||||||||||||||
| 31 | } | ||||||||||||||
| 32 | } | ||||||||||||||
| 33 | } | ||||||||||||||
| 34 | |||||||||||||||
| 35 | |||||||||||||||
| 36 | 6 | ▶ | sub _database { | ||||||||||||
|
Subroutine
_database: called CC=3 SCAR=14.2
| |||||||||||||||
| 37 | 6 | my $self = shift; | |||||||||||||
| 38 | 6 | my %args = @_; | |||||||||||||
| 39 | |||||||||||||||
| 40 | 6 | ▶ | if ($ENV{DBIO_TEST_DUCKDB_DSN}) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 41 | return ( | ||||||||||||||
| 42 | 0 | ▶ | (map { $ENV{"DBIO_TEST_DUCKDB_${_}"} // '' } qw/DSN DBUSER DBPASS/), | ||||||||||||
|
Condition0%0/2
$ENV{"DBIO_TEST_DUCKDB_$_"} // ""
MC/DC0%0/1
$ENV{"DBIO_TEST_DUCKDB_$_"} // ""
$ENV{"DBIO_TEST_DUCKDB_$_"}
Truth table0%0/2
A
A= $ENV{"DBIO_TEST_DUCKDB_$_"}
| |||||||||||||||
| 43 | { AutoCommit => 1, RaiseError => 1, PrintError => 0, %args }, | ||||||||||||||
| 44 | ); | ||||||||||||||
| 45 | } | ||||||||||||||
| 46 | |||||||||||||||
| 47 | return ( | ||||||||||||||
| 48 | 6 | 'dbi:DuckDB:dbname=:memory:', | |||||||||||||
| 49 | '', '', | ||||||||||||||
| 50 | { AutoCommit => 1, RaiseError => 1, PrintError => 0, %args }, | ||||||||||||||
| 51 | ); | ||||||||||||||
| 52 | } | ||||||||||||||
| 53 | |||||||||||||||
| 54 | |||||||||||||||
| 55 | 6 | ▶ | sub init_schema { | ||||||||||||
|
Subroutine
init_schema: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 56 | 6 | my $self = shift; | |||||||||||||
| 57 | 6 | my %args = @_; | |||||||||||||
| 58 | |||||||||||||||
| 59 | 6 | my ($dsn, $user, $pass, $opts) = $self->_database(%args); | |||||||||||||
| 60 | |||||||||||||||
| 61 | 6 | return DBIO::Test->init_schema( | |||||||||||||
| 62 | dsn => $dsn, | ||||||||||||||
| 63 | user => $user, | ||||||||||||||
| 64 | pass => $pass, | ||||||||||||||
| 65 | connect_opts => $opts, | ||||||||||||||
| 66 | storage_type => '+DBIO::DuckDB::Storage', | ||||||||||||||
| 67 | %args, | ||||||||||||||
| 68 | ); | ||||||||||||||
| 69 | } | ||||||||||||||
| 70 | |||||||||||||||
| 71 | 8 | 1; | |||||||||||||
| 72 | |||||||||||||||
| 73 | __END__ | ||||||||||||||
| 74 | |||||||||||||||
| 75 | =pod | ||||||||||||||
| 76 | |||||||||||||||
| 77 | =encoding UTF-8 | ||||||||||||||
| 78 | |||||||||||||||
| 79 | =head1 NAME | ||||||||||||||
| 80 | |||||||||||||||
| 81 | DBIO::DuckDB::Test - DuckDB-specific test utilities for DBIO | ||||||||||||||
| 82 | |||||||||||||||
| 83 | =head1 VERSION | ||||||||||||||
| 84 | |||||||||||||||
| 85 | version 0.900001 | ||||||||||||||
| 86 | |||||||||||||||
| 87 | =head1 SYNOPSIS | ||||||||||||||
| 88 | |||||||||||||||
| 89 | use DBIO::DuckDB::Test; | ||||||||||||||
| 90 | |||||||||||||||
| 91 | my $schema = DBIO::DuckDB::Test->init_schema; | ||||||||||||||
| 92 | my $rs = $schema->resultset('Artist'); | ||||||||||||||
| 93 | |||||||||||||||
| 94 | =head1 DESCRIPTION | ||||||||||||||
| 95 | |||||||||||||||
| 96 | Extends L<DBIO::Test> with DuckDB-specific test helpers for the | ||||||||||||||
| 97 | L<DBIO::DuckDB> driver distribution. Mirrors L<DBIO::SQLite::Test>: | ||||||||||||||
| 98 | driver tests call C<< DBIO::DuckDB::Test->init_schema >> and get a | ||||||||||||||
| 99 | connected, deployed schema backed by an in-memory DuckDB. | ||||||||||||||
| 100 | |||||||||||||||
| 101 | =head1 METHODS | ||||||||||||||
| 102 | |||||||||||||||
| 103 | =head2 _database | ||||||||||||||
| 104 | |||||||||||||||
| 105 | Returns C<($dsn, $user, $pass, \%opts)> for C<< $schema->connect() >>. | ||||||||||||||
| 106 | Honours C<DBIO_TEST_DUCKDB_DSN> if set, otherwise uses | ||||||||||||||
| 107 | C<dbi:DuckDB:dbname=:memory:>. | ||||||||||||||
| 108 | |||||||||||||||
| 109 | =head2 init_schema | ||||||||||||||
| 110 | |||||||||||||||
| 111 | my $schema = DBIO::DuckDB::Test->init_schema(%opts); | ||||||||||||||
| 112 | |||||||||||||||
| 113 | Thin wrapper around L<DBIO::Test/init_schema>. Fills in C<dsn> and | ||||||||||||||
| 114 | C<storage_type> for DuckDB (honouring C<DBIO_TEST_DUCKDB_DSN>) and then | ||||||||||||||
| 115 | delegates to the core harness. | ||||||||||||||
| 116 | |||||||||||||||
| 117 | Core's C<deploy_schema> calls C<< $schema->deploy >>, which | ||||||||||||||
| 118 | L<DBIO::Schema/deploy> routes through C<dbio_deploy_class> when set on | ||||||||||||||
| 119 | the storage class -- so DuckDB deployment goes through | ||||||||||||||
| 120 | L<DBIO::DuckDB::Deploy> (the native test-and-compare path), not | ||||||||||||||
| 121 | SQL::Translator. No extra install step needed here. | ||||||||||||||
| 122 | |||||||||||||||
| 123 | =head1 AUTHOR | ||||||||||||||
| 124 | |||||||||||||||
| 125 | DBIO Authors | ||||||||||||||
| 126 | |||||||||||||||
| 127 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||
| 128 | |||||||||||||||
| 129 | Copyright (C) 2026 DBIO Authors | ||||||||||||||
| 130 | |||||||||||||||
| 131 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||
| 132 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||
| 133 | |||||||||||||||
| 134 | =cut | ||||||||||||||