Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #53

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: run-tests
run-name: Run tests
on: [push]
jobs:
run:
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
operating-system: [ubuntu-latest]
php-versions: ['7.4', '8.0', '8.1']
name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }}
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: intl pcre pdo #optional
- name: Check PHP Version
run: php -v
- name: Install Composer
run: composer install
- name: Psalm
run: php vendor/bin/psalm
- name: PHP CodeSniffer
run: php vendor/bin/phpcs
- name: Copy phpunit.xml.dist
run: cp phpunit.xml.dist phpunit.xml
- name: PhpUnit
run: php vendor/bin/phpunit
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ vendor/
phpunit.xml
Vagrantfile
puphpet/
.vagrant/
.vagrant/
/.phpunit.result.cache
27 changes: 0 additions & 27 deletions .travis.yml

This file was deleted.

4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,7 @@ doctrine:
* [Data Retrieval And Manipulation](http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/data-retrieval-and-manipulation.html)
* [SQL Query Builder](http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/query-builder.html)
* [Schema-Representation](http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/schema-representation.html)

# ClickHouse Error Codes list

* https://github.com/ClickHouse/ClickHouse/blob/master/src/Common/ErrorCodes.cpp
18 changes: 13 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,18 @@
}
],
"require": {
"php": "^7.1",
"php": "^7.4 || ^8.0",
"ext-PDO": "*",
"ext-pcre": "*",
"doctrine/dbal": "^2.7",
"smi2/phpClickHouse": "^1.0"
"doctrine/dbal": "^3.0",
"smi2/phpclickhouse": "^1.0"
},
"require-dev": {
"doctrine/coding-standard": "^4.0",
"phpunit/phpunit": "^7.0"
"doctrine/coding-standard": "^10.0",
"phpunit/phpunit": "^9.0",
"squizlabs/php_codesniffer": "^3.7",
"slevomat/coding-standard": "^8.6",
"vimeo/psalm": "^4.29"
},
"autoload": {
"psr-4": {
Expand All @@ -40,5 +43,10 @@
"psr-4": {
"FOD\\DBALClickHouse\\Tests\\": "tests/"
}
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
9 changes: 9 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: '3.9'

services:

clickhouse:
image: clickhouse/clickhouse-server
ports:
- 8123:8123
- 9000:9000
20 changes: 20 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>

<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">

<arg name="basepath" value="."/>
<arg name="cache" value=".phpcs-cache"/>
<arg name="colors"/>
<arg name="extensions" value="php"/>

<config name="installed_paths" value="vendor/slevomat/coding-standard"/>

<rule ref="PSR12">
<exclude name="PSR2.Methods.MethodDeclaration.Underscore"/>
<exclude name="Generic.Files.LineLength.TooLong"/>
</rule>

<file>src/</file>
<file>tests/</file>
</ruleset>
15 changes: 15 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<psalm
errorLevel="8"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
</psalm>
48 changes: 10 additions & 38 deletions src/ClickHouseConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@
namespace FOD\DBALClickHouse;

use ClickHouseDB\Client as Smi2CHClient;
use ClickHouseDB\Exception\TransportException;
use Doctrine\DBAL\Driver\Connection;
use Doctrine\DBAL\Driver\PingableConnection;
use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
use Doctrine\DBAL\Driver\Result;
use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Platforms\AbstractPlatform;

use function array_merge;
use function func_get_args;

/**
* ClickHouse implementation for the Connection interface.
*/
class ClickHouseConnection implements Connection, PingableConnection, ServerInfoAwareConnection
class ClickHouseConnection implements Connection
{
/** @var Smi2CHClient */
protected $smi2CHClient;
Expand Down Expand Up @@ -60,21 +60,21 @@ public function __construct(
/**
* {@inheritDoc}
*/
public function prepare($prepareString)
public function prepare(string $sql): Statement
{
return new ClickHouseStatement($this->smi2CHClient, $prepareString, $this->platform);
return new ClickHouseStatement($this->smi2CHClient, $sql, $this->platform);
}

/**
* {@inheritDoc}
*/
public function query()
public function query(string $sql): Result
{
$args = func_get_args();
$stmt = $this->prepare($args[0]);
$stmt->execute();

return $stmt;
return new ClickHouseResult($stmt);
}

/**
Expand All @@ -92,9 +92,9 @@ public function quote($input, $type = ParameterType::STRING)
/**
* {@inheritDoc}
*/
public function exec($statement) : int
public function exec(string $sql): int
{
$stmt = $this->prepare($statement);
$stmt = $this->prepare($sql);
$stmt->execute();

return $stmt->rowCount();
Expand Down Expand Up @@ -147,32 +147,4 @@ public function errorInfo()
{
throw new \LogicException('You need to implement ClickHouseConnection::errorInfo()');
}

/**
* {@inheritDoc}
*/
public function ping()
{
return $this->smi2CHClient->ping();
}

/**
* {@inheritDoc}
*/
public function getServerVersion()
{
try {
return $this->smi2CHClient->getServerVersion();
} catch (TransportException $exception) {
return '';
}
}

/**
* {@inheritDoc}
*/
public function requiresQueryForServerVersion()
{
return true;
}
}
Loading