Skip to content
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
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"ext-curl": "*",
"ext-json": "*",
"guzzlehttp/guzzle": "^7.9",
"guzzlehttp/psr7": "^1.7 || ^2.0"
"guzzlehttp/psr7": "^1.7 || ^2.0",
"ramsey/uuid": "^4.9"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.5",
Expand Down
11 changes: 6 additions & 5 deletions src/LitebaseClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Exception;
use GuzzleHttp\Client;
use Litebase\OpenAPI\Model\StatementParameter;
use Ramsey\Uuid\Uuid;
use Throwable;

class LitebaseClient
Expand Down Expand Up @@ -61,7 +62,7 @@ public function beginTransaction(): bool
try {
$response = $this->transport->send(
new Query(
id: uniqid(),
id: Uuid::uuid4()->toString(),
statement: 'BEGIN',
)
);
Expand Down Expand Up @@ -100,7 +101,7 @@ public function commit(): bool
try {
$this->transport->send(
new Query(
id: uniqid(),
id: Uuid::uuid4()->toString(),
transactionId: $this->transaction->id,
statement: 'COMMIT',
)
Expand Down Expand Up @@ -141,7 +142,7 @@ public function errorInfo(): array
public function exec(array $input): ?QueryResult
{
// Set a unique id for the request.
$input['id'] = uniqid();
$input['id'] = Uuid::uuid4()->toString();

if ($this->transaction) {
$input['transaction_id'] = $this->transaction->id;
Expand Down Expand Up @@ -198,7 +199,7 @@ public function rollback(): bool

$this->transport->send(
new Query(
id: uniqid(),
id: Uuid::uuid4()->toString(),
transactionId: $this->transaction->id,
statement: 'ROLLBACK',
)
Expand All @@ -219,7 +220,7 @@ public function withTransport(string $transportType): LitebaseClient
$this->transport = new HttpStreamingTransport($this->configuration);
break;
default:
throw new Exception('Invalid transport type: '.$transportType);
throw new Exception('Invalid transport type: ' . $transportType);
}

return $this;
Expand Down
3 changes: 2 additions & 1 deletion tests/Unit/HttpTransportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Litebase\HttpTransport;
use Litebase\Query;
use Litebase\QueryResult;
use Ramsey\Uuid\Uuid;

describe('HttpTransport', function () {
$mock = new MockHandler;
Expand Down Expand Up @@ -65,7 +66,7 @@
$transport->setClient(new ApiClient($configuration, $httpClient));

$query = new Query(
id: 'test-query',
id: Uuid::uuid4()->toString(),
statement: 'SELECT 1',
parameters: [],
);
Expand Down