Skip to content

Commit

Permalink
feat: pass parameters natively via http interface along the query
Browse files Browse the repository at this point in the history
  • Loading branch information
simPod committed Jan 16, 2024
1 parent 72a23fd commit 5fe7db9
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 36 deletions.
28 changes: 14 additions & 14 deletions tests/Client/InsertTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ public function testInsert(string $tableSql): void
['PageViews' => 6, 'UserID' => 4324182021466249494, 'Duration' => 185, 'Sign' => 1],
];

$this->client->executeQuery($tableSql);
self::$client->executeQuery($tableSql);

$this->client->insert('UserActivity', $data);
self::$client->insert('UserActivity', $data);

$output = $this->client->select(
$output = self::$client->select(
<<<'CLICKHOUSE'
SELECT * FROM UserActivity
CLICKHOUSE,
Expand All @@ -57,9 +57,9 @@ public function testInsertUseColumns(string $tableSql): void
['PageViews' => 6, 'UserID' => '4324182021466249494', 'Duration' => 185, 'Sign' => 1],
];

$this->client->executeQuery($tableSql);
self::$client->executeQuery($tableSql);

$this->client->insert(
self::$client->insert(
'UserActivity',
[
[5, 4324182021466249494, 146, -1],
Expand All @@ -68,7 +68,7 @@ public function testInsertUseColumns(string $tableSql): void
['PageViews', 'UserID', 'Duration', 'Sign'],
);

$output = $this->client->select(
$output = self::$client->select(
<<<'CLICKHOUSE'
SELECT * FROM UserActivity
CLICKHOUSE,
Expand All @@ -80,7 +80,7 @@ public function testInsertUseColumns(string $tableSql): void

public function testInsertEscaping(): void
{
$this->client->executeQuery(
self::$client->executeQuery(
<<<'CLICKHOUSE'
CREATE TABLE a (
b Nullable(String)
Expand All @@ -94,9 +94,9 @@ public function testInsertEscaping(): void
["\t"],
];

$this->client->insert('a', $expectedData);
self::$client->insert('a', $expectedData);

$output = $this->client->select(
$output = self::$client->select(
<<<'CLICKHOUSE'
SELECT * FROM a
CLICKHOUSE,
Expand Down Expand Up @@ -124,7 +124,7 @@ public static function providerInsert(): iterable

public function testInsertWithFormat(): void
{
$this->client->executeQuery(
self::$client->executeQuery(
<<<'CLICKHOUSE'
CREATE TABLE UserActivity (
PageViews UInt32,
Expand All @@ -136,7 +136,7 @@ public function testInsertWithFormat(): void
CLICKHOUSE,
);

$this->client->insertWithFormat(
self::$client->insertWithFormat(
'UserActivity',
new JsonEachRow(),
<<<'JSONEACHROW'
Expand All @@ -145,7 +145,7 @@ public function testInsertWithFormat(): void
JSONEACHROW,
);

$output = $this->client->select(
$output = self::$client->select(
<<<'CLICKHOUSE'
SELECT * FROM UserActivity
CLICKHOUSE
Expand All @@ -166,13 +166,13 @@ public function testInsertEmptyValuesThrowsException(): void
{
$this->expectException(CannotInsert::class);

$this->client->insert('table', []);
self::$client->insert('table', []);
}

public function testInsertToNonExistentTableExpectServerError(): void
{
$this->expectException(ServerError::class);

$this->client->insert('table', [[1]]);
self::$client->insert('table', [[1]]);
}
}
12 changes: 6 additions & 6 deletions tests/Client/SelectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ final class SelectTest extends TestCaseBase

public function testSelectWithParams(): void
{
$client = $this->client;
$client = self::$client;
$output = $client->selectWithParams('SELECT {p1:UInt8} AS data', ['p1' => 3], new TabSeparated());

self::assertSame("3\n", $output->contents);
Expand All @@ -43,7 +43,7 @@ public function testSelectWithParams(): void
#[DataProvider('providerJson')]
public function testJson(mixed $expectedData, string $sql): void
{
$client = $this->client;
$client = self::$client;
$output = $client->select($sql, new Json());

self::assertSame($expectedData, $output->data);
Expand Down Expand Up @@ -82,7 +82,7 @@ public static function providerJson(): iterable
#[DataProvider('providerJsonCompact')]
public function testJsonCompact(mixed $expectedData, string $sql): void
{
$client = $this->client;
$client = self::$client;
$output = $client->select($sql, new JsonCompact());

self::assertSame($expectedData, $output->data);
Expand Down Expand Up @@ -121,7 +121,7 @@ public static function providerJsonCompact(): iterable
#[DataProvider('providerJsonEachRow')]
public function testJsonEachRow(mixed $expectedData, string $sql): void
{
$client = $this->client;
$client = self::$client;
$output = $client->select($sql, new JsonEachRow());

self::assertSame($expectedData, $output->data);
Expand Down Expand Up @@ -159,7 +159,7 @@ public static function providerJsonEachRow(): iterable

public function testNull(): void
{
$client = $this->client;
$client = self::$client;
$client->select('SELECT 1', new Null_());

self::assertTrue(true);
Expand All @@ -170,6 +170,6 @@ public function testSettingsArePassed(): void
self::expectException(ServerError::class);
$this->expectExceptionMessageMatches("~DB::Exception: Database `non-existent` (doesn't|does not) exist~");

$this->client->select('SELECT 1', new JsonCompact(), ['database' => 'non-existent']);
self::$client->select('SELECT 1', new JsonCompact(), ['database' => 'non-existent']);
}
}
2 changes: 1 addition & 1 deletion tests/Snippet/CurrentDatabaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function testRun(): void
{
self::assertSame(
$this->currentDbName,
CurrentDatabase::run($this->client),
CurrentDatabase::run(self::$client),
);
}
}
10 changes: 5 additions & 5 deletions tests/Snippet/DatabaseSizeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class DatabaseSizeTest extends TestCaseBase

public function setUp(): void
{
$this->client->executeQuery(
self::$client->executeQuery(
<<<'CLICKHOUSE'
CREATE TABLE test (
a_date DateTime,
Expand All @@ -33,9 +33,9 @@ public function setUp(): void

public function testRun(): void
{
self::assertSame(0, DatabaseSize::run($this->client));
self::assertSame(0, DatabaseSize::run(self::$client));

$this->client->insert('test', [[new DateTimeImmutable('2020-08-01 00:11:22'), 1]]);
self::$client->insert('test', [[new DateTimeImmutable('2020-08-01 00:11:22'), 1]]);

if (ClickHouseVersion::get() >= 2307) {
$expectedSize = 316;
Expand All @@ -45,11 +45,11 @@ public function testRun(): void
$expectedSize = 150;
}

self::assertSame($expectedSize, DatabaseSize::run($this->client));
self::assertSame($expectedSize, DatabaseSize::run(self::$client));
}

public function tearDown(): void
{
$this->client->executeQuery('DROP TABLE test');
self::$client->executeQuery('DROP TABLE test');
}
}
2 changes: 1 addition & 1 deletion tests/Snippet/PartsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ final class PartsTest extends TestCaseBase

public function testRun(): void
{
self::assertSame([], Parts::run($this->client, 'system.query_log'));
self::assertSame([], Parts::run(self::$client, 'system.query_log'));
}
}
4 changes: 2 additions & 2 deletions tests/Snippet/ShowCreateTableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public function testRun(): void
CREATE TABLE $dbName.test (`date` Date) ENGINE = Memory
CLICKHOUSE;

$this->client->executeQuery($sql);
self::$client->executeQuery($sql);

$createTableSql = ShowCreateTable::run($this->client, 'test');
$createTableSql = ShowCreateTable::run(self::$client, 'test');

// BC
$createTableSql = str_replace(
Expand Down
2 changes: 1 addition & 1 deletion tests/Snippet/ShowDatabasesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ final class ShowDatabasesTest extends TestCaseBase

public function testRun(): void
{
$databases = ShowDatabases::run($this->client);
$databases = ShowDatabases::run(self::$client);
self::assertGreaterThan(2, count($databases)); // Default, system, at least one test database

$databases = array_filter(
Expand Down
10 changes: 5 additions & 5 deletions tests/Snippet/TableSizesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final class TableSizesTest extends TestCaseBase

public function setUp(): void
{
$this->client->executeQuery(
self::$client->executeQuery(
<<<'CLICKHOUSE'
CREATE TABLE test (
a_date DateTime,
Expand All @@ -32,18 +32,18 @@ public function setUp(): void

public function testRun(): void
{
$this->client->insert('test', [[new DateTimeImmutable(), 1]]);
self::$client->insert('test', [[new DateTimeImmutable(), 1]]);

self::assertCount(1, TableSizes::run($this->client));
self::assertCount(1, TableSizes::run(self::$client));
}

public function testRunOnNonexistentDatabase(): void
{
self::assertSame([], TableSizes::run($this->client, 'does not exist'));
self::assertSame([], TableSizes::run(self::$client, 'does not exist'));
}

public function tearDown(): void
{
$this->client->executeQuery('DROP TABLE test');
self::$client->executeQuery('DROP TABLE test');
}
}
2 changes: 1 addition & 1 deletion tests/Snippet/VersionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ final class VersionTest extends TestCaseBase

public function testRun(): void
{
self::assertMatchesRegularExpression('~(\d+\.)+\d+~', Version::run($this->client));
self::assertMatchesRegularExpression('~(\d+\.)+\d+~', Version::run(self::$client));
}
}

0 comments on commit 5fe7db9

Please sign in to comment.