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

Get Connection Id #472

Merged
merged 4 commits into from
Nov 7, 2024
Merged
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
14 changes: 14 additions & 0 deletions src/Database/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,13 @@ abstract public function getSupportForBatchOperations(): bool;
*/
abstract public function getSupportForAttributeResizing(): bool;

/**
* Is get connection id supported?
*
* @return bool
*/
abstract public function getSupportForGetConnectionId(): bool;

/**
* Get current attribute count from collection document
*
Expand Down Expand Up @@ -1001,4 +1008,11 @@ public function escapeWildcards(string $value): string
* @throws Exception
*/
abstract public function increaseDocumentAttribute(string $collection, string $id, string $attribute, int|float $value, string $updatedAt, int|float|null $min = null, int|float|null $max = null): bool;

/**
* Returns the connection ID identifier
*
* @return string
*/
abstract public function getConnectionId(): string;
}
9 changes: 9 additions & 0 deletions src/Database/Adapter/MariaDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -2398,4 +2398,13 @@ protected function processException(PDOException $e): void

throw $e;
}

/**
* @return string
*/
public function getConnectionId(): string
{
$stmt = $this->getPDO()->query("SELECT CONNECTION_ID();");
return $stmt->fetchColumn();
}
}
15 changes: 15 additions & 0 deletions src/Database/Adapter/Mongo.php
Original file line number Diff line number Diff line change
Expand Up @@ -1777,6 +1777,16 @@ public function getSupportForBatchOperations(): bool
return false;
}

/**
* Is get connection id supported?
*
* @return bool
*/
public function getSupportForGetConnectionId(): bool
{
return false;
}

/**
* Get current attribute count from collection document
*
Expand Down Expand Up @@ -1926,4 +1936,9 @@ public function getMaxIndexLength(): int
{
return 0;
}

public function getConnectionId(): string
{
return '0';
}
}
9 changes: 9 additions & 0 deletions src/Database/Adapter/Postgres.php
Original file line number Diff line number Diff line change
Expand Up @@ -2392,4 +2392,13 @@ protected function processException(PDOException $e): void

throw $e;
}

/**
* @return string
*/
public function getConnectionId(): string
{
$stmt = $this->getPDO()->query("SELECT pg_backend_pid();");
return $stmt->fetchColumn();
}
}
10 changes: 10 additions & 0 deletions src/Database/Adapter/SQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,16 @@ public function getSupportForBatchOperations(): bool
return true;
}

/**
* Is get connection id supported?
*
* @return bool
*/
public function getSupportForGetConnectionId(): bool
{
return true;
}

/**
* Get current attribute count from collection document
*
Expand Down
10 changes: 10 additions & 0 deletions src/Database/Adapter/SQLite.php
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,16 @@ public function getSupportForAttributeResizing(): bool
return false;
}

/**
* Is get connection id supported?
*
* @return bool
*/
public function getSupportForGetConnectionId(): bool
{
return false;
}

/**
* Get SQL Index Type
*
Expand Down
11 changes: 11 additions & 0 deletions src/Database/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,17 @@ public function silent(callable $callback, array $listeners = null): mixed
}
}

/**
* Get getConnection Id
*
* @return string
* @throws Exception
*/
public function getConnectionId(): string
{
return $this->adapter->getConnectionId();
}

/**
* Skip relationships for all the calls inside the callback
*
Expand Down
10 changes: 10 additions & 0 deletions tests/e2e/Adapter/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@ public function testUpdateDeleteCollectionNotFound(): void
}
}

public function testGetCollectionId(): void
{
if (!static::getDatabase()->getAdapter()->getSupportForGetConnectionId()) {
$this->expectNotToPerformAssertions();
return;
}

$this->assertIsString(static::getDatabase()->getConnectionId());
}

public function testDeleteRelatedCollection(): void
{
if (!static::getDatabase()->getAdapter()->getSupportForRelationships()) {
Expand Down
Loading