Skip to content

Commit 3ec6684

Browse files
authored
Merge pull request #546 from utopia-php/feat-pool-adapter
Feat pool adapter
2 parents ad191bf + b84273e commit 3ec6684

File tree

18 files changed

+668
-138
lines changed

18 files changed

+668
-138
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ jobs:
7777
Postgres,
7878
SQLite,
7979
Mirror,
80+
Pool,
8081
SharedTables/MariaDB,
8182
SharedTables/MySQL,
8283
SharedTables/Postgres,

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,10 @@ The database document interface only supports primitives types (`strings`, `inte
4949
Below is a list of supported databases, and their compatibly tested versions alongside a list of supported features and relevant limits.
5050

5151
| Adapter | Status | Version |
52-
| -------- | ------ | ------- |
52+
|----------|--------|---------|
5353
| MariaDB || 10.5 |
5454
| MySQL || 8.0 |
5555
| Postgres || 13.0 |
56-
| MongoDB || 5.0 |
5756
| SQLite || 3.38 |
5857

5958
` ✅ - supported `

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
"ext-pdo": "*",
3838
"ext-mbstring": "*",
3939
"utopia-php/framework": "0.33.*",
40-
"utopia-php/cache": "0.12.*"
40+
"utopia-php/cache": "0.12.*",
41+
"utopia-php/pools": "0.8.*"
4142
},
4243
"require-dev": {
4344
"fakerphp/faker": "1.23.*",

composer.lock

Lines changed: 79 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Database/Adapter.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ abstract class Adapter
2020

2121
protected bool $tenantPerDocument = false;
2222

23+
protected int $timeout = 0;
24+
2325
protected int $inTransaction = 0;
2426

2527
/**
@@ -275,13 +277,18 @@ public function resetMetadata(): static
275277
* and an appropriate error or exception will be raised to handle the timeout condition.
276278
*
277279
* @param int $milliseconds The timeout value in milliseconds for database queries.
278-
* @param string $event The event the timeout should fire fore
280+
* @param string $event The event the timeout should fire for
279281
* @return void
280282
*
281283
* @throws Exception The provided timeout value must be greater than or equal to 0.
282284
*/
283285
abstract public function setTimeout(int $milliseconds, string $event = Database::EVENT_ALL): void;
284286

287+
public function getTimeout(): int
288+
{
289+
return $this->timeout;
290+
}
291+
285292
/**
286293
* Clears a global timeout for database queries.
287294
*
@@ -963,22 +970,22 @@ abstract public function getCountOfIndexes(Document $collection): int;
963970
*
964971
* @return int
965972
*/
966-
abstract public static function getCountOfDefaultAttributes(): int;
973+
abstract public function getCountOfDefaultAttributes(): int;
967974

968975
/**
969976
* Returns number of indexes used by default.
970977
*
971978
* @return int
972979
*/
973-
abstract public static function getCountOfDefaultIndexes(): int;
980+
abstract public function getCountOfDefaultIndexes(): int;
974981

975982
/**
976983
* Get maximum width, in bytes, allowed for a SQL row
977984
* Return 0 when no restrictions apply
978985
*
979986
* @return int
980987
*/
981-
abstract public static function getDocumentSizeLimit(): int;
988+
abstract public function getDocumentSizeLimit(): int;
982989

983990
/**
984991
* Estimate maximum number of bytes required to store a document in $collection.

src/Database/Adapter/MariaDB.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2312,6 +2312,8 @@ public function setTimeout(int $milliseconds, string $event = Database::EVENT_AL
23122312
throw new DatabaseException('Timeout must be greater than 0');
23132313
}
23142314

2315+
$this->timeout = $milliseconds;
2316+
23152317
$seconds = $milliseconds / 1000;
23162318

23172319
$this->before($event, 'timeout', function ($sql) use ($seconds) {

src/Database/Adapter/MySQL.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ public function setTimeout(int $milliseconds, string $event = Database::EVENT_AL
2525
if ($milliseconds <= 0) {
2626
throw new DatabaseException('Timeout must be greater than 0');
2727
}
28+
29+
$this->timeout = $milliseconds;
30+
2831
$this->before($event, 'timeout', function ($sql) use ($milliseconds) {
2932
return \preg_replace(
3033
pattern: '/SELECT/',

0 commit comments

Comments
 (0)