Skip to content

Commit

Permalink
Get connection id
Browse files Browse the repository at this point in the history
  • Loading branch information
fogelito committed Nov 5, 2024
1 parent f716bcc commit a32165c
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Database/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,13 @@ abstract public function getSupportForBatchOperations(): bool;
*/
abstract public function getSupportForAttributeResizing(): bool;

/**
* Are attributes supported?
*
* @return bool
*/
abstract public function getSupportForGetConnectionId(): bool;

/**
* Get current attribute count from collection document
*
Expand Down Expand Up @@ -980,4 +987,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 @@ -2337,4 +2337,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 @@ -375,6 +375,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 @@ -866,6 +866,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
12 changes: 12 additions & 0 deletions tests/e2e/Adapter/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,18 @@ public function testUpdateDeleteCollectionNotFound(): void
}
}

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

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

$this->assertEquals(999, 11111);
}

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

0 comments on commit a32165c

Please sign in to comment.