Skip to content

Commit

Permalink
switch database driver with MariaDB
Browse files Browse the repository at this point in the history
  • Loading branch information
Songmu committed Apr 6, 2024
1 parent c8cd99e commit b1d3630
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ jobs:
perl-version: ${{ matrix.perl }}
- run: |
author/ci_install_mysql.sh
cpanm --quiet --installdeps --notest --with-recommends .
cpanm --quiet --installdeps --notest .
if [[ "DATABASE_ADAPTER" == "mariadb" ]]; then
cpanm DBD::MariaDB
else
cpanm DBD::mysql
fi
prove -lvr
env:
DATABASE_ADAPTER: ${{ matrix.mysql }}
3 changes: 2 additions & 1 deletion cpanfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
requires 'Class::Accessor::Lite';
requires 'DBD::mysql';
recommends 'DBD::mysql';
recommends 'DBD::MariaDB';
requires 'DBI';
requires 'File::Copy::Recursive';
requires 'File::Temp';
Expand Down
19 changes: 18 additions & 1 deletion lib/Test/mysqld.pm
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@ use File::Temp qw(tempdir);
use POSIX qw(SIGTERM WNOHANG);
use Time::HiRes qw(sleep);

my $driver = 'mysql';
BEGIN {
eval {
require DBD::mysql;
};
if ($@) {
eval {
require DBD::MariaDB;
$driver = 'MariaDB';
};
if ($@) {
die "DBD::mysql or DBD::MariaDB is required to use Test::mysqld";
}
}
}

our $VERSION = '1.0020';

our $errstr;
Expand All @@ -27,6 +43,7 @@ my %Defaults = (
pid => undef,
copy_data_from => undef,
_owner_pid => undef,
driver => $driver,
);

Class::Accessor::Lite->mk_accessors(keys %Defaults);
Expand Down Expand Up @@ -97,7 +114,7 @@ sub dsn {
}
}
$args{dbname} ||= 'test';
return 'DBI:mysql:' . join(';', map { "$_=$args{$_}" } sort keys %args);
return "DBI:$self->{driver}:" . join(';', map { "$_=$args{$_}" } sort keys %args);
}

sub start {
Expand Down

0 comments on commit b1d3630

Please sign in to comment.