App-Sqitch
view release on metacpan or search on metacpan
lib/App/Sqitch/Engine/clickhouse.pm view on Meta::CPAN
);
# Add relevant query args.
my $have_port = $self->_clickcnf->{port} || 0;
if (my @p = $uri->query_params) {
while (@p) {
my ($k, $v) = (lc shift @p, shift @p);
if ($k eq 'sslmode') {
# Prefer secure connectivity if SSL mode specified.
push @ret => '--secure';
} elsif ($k eq 'nativeport') {
# Custom config to set the CLI port, which is different
# from the HTTP port used by the ODBC driver.
push @ret => '--port', $v;
$have_port = 1;
}
}
}
# If no port from config or query params, set it to encrypted port
# 9440 if the URL port is an HTTPS port.
if (!$have_port) {
my $http_port = $uri->port;
push @ret => '--port', 9440 if $http_port == 8443 || $http_port == 443;
}
return \@ret;
}
sub cli { @{ shift->_cli } }
sub key { 'clickhouse' }
sub name { 'ClickHouse' }
sub driver { 'DBD::ODBC 1.59' }
sub default_client {
my $self = shift;
my $ext = App::Sqitch::ISWIN || $^O eq 'cygwin' ? '.exe' : '';
# Try to find the client in the path.
my @names = map { $_ . $ext } 'clickhouse', 'clickhouse-client';
for my $dir (File::Spec->path) {
for my $try ( @names ) {
my $path = file $dir, $try;
# GetShortPathName returns undef for nonexistent files.
$path = Win32::GetShortPathName($path) // next if App::Sqitch::ISWIN;
return $try if -f $path && -x $path;
}
}
hurl clickhouse => __x(
'Unable to locate {cli} client; set "engine.{eng}.client" via sqitch config',
cli => 'clickhouse',
eng => 'clickhouse',
);
}
sub _char2ts { $_[1]->set_time_zone('UTC')->iso8601 }
sub _ts2char_format {
q{formatDateTime(%s, 'year:%%Y:month:%%m:day:%%d:hour:%%H:minute:%%i:second:%%S:time_zone:UTC')};
}
sub _log_tags_param {
[ map { $_->format_name } $_[1]->tags ];
}
sub _log_requires_param {
[ map { $_->as_string } $_[1]->requires ];
}
sub _log_conflicts_param {
[ map { $_->as_string } $_[1]->conflicts ];
}
sub _limit_offset {
# LIMIT/OFFSET don't support parameters, alas. So just put them in the query.
my ($self, $lim, $off) = @_;
return ["LIMIT $lim", "OFFSET $off"], [] if $lim && $off;
return ["LIMIT $lim"], [] if $lim;
return ["OFFSET $off"], [] if $off;
return [], [];
}
# ClickHouse ODBC does not support arrays. So we must parse them manually.
# I'd rather not do an eval, so rip this out once the issue is fixed.
# https://github.com/clickHouse/clickhouse-odbc/issues/525
sub _parse_array {
no utf8;
return [] unless $_[1];
my $list = eval $_[1];
return [] unless $list;
shift @{ $list } if @{ $list } && $list->[0] eq '';
return $list;
}
sub _version_query { 'SELECT CAST(ROUND(MAX(version), 1) AS CHAR) FROM releases' }
sub _initialized {
my $self = shift;
return try {
$self->dbh->selectcol_arrayref(q{
SELECT true
FROM information_schema.tables
WHERE TABLE_CATALOG = current_database()
AND TABLE_SCHEMA = ?
AND TABLE_NAME = ?
}, undef, $self->registry, 'changes')->[0]
} catch {
return 0 if $DBI::state && $DBI::state eq 'HY000';
die $_;
}
}
sub _initialize {
my $self = shift;
hurl engine => __x(
'Sqitch database {database} already initialized',
database => $self->registry,
) if $self->initialized;
( run in 1.007 second using v1.01-cache-2.11-cpan-99c4e6809bf )