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
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ jobs:
Postgres,
SQLite,
Mirror,
Pool,
SharedTables/MariaDB,
SharedTables/MySQL,
SharedTables/Postgres,
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,10 @@ The database document interface only supports primitives types (`strings`, `inte
Below is a list of supported databases, and their compatibly tested versions alongside a list of supported features and relevant limits.

| Adapter | Status | Version |
| -------- | ------ | ------- |
|----------|--------|---------|
| MariaDB | ✅ | 10.5 |
| MySQL | ✅ | 8.0 |
| Postgres | ✅ | 13.0 |
| MongoDB | ✅ | 5.0 |
| SQLite | ✅ | 3.38 |

` ✅ - supported `
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
"ext-pdo": "*",
"ext-mbstring": "*",
"utopia-php/framework": "0.33.*",
"utopia-php/cache": "0.12.*"
"utopia-php/cache": "0.12.*",
"utopia-php/pools": "0.8.*"
},
"require-dev": {
"fakerphp/faker": "1.23.*",
Expand Down
106 changes: 79 additions & 27 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 11 additions & 4 deletions src/Database/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ abstract class Adapter

protected bool $tenantPerDocument = false;

protected int $timeout = 0;

protected int $inTransaction = 0;

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

public function getTimeout(): int
{
return $this->timeout;
}

/**
* Clears a global timeout for database queries.
*
Expand Down Expand Up @@ -963,22 +970,22 @@ abstract public function getCountOfIndexes(Document $collection): int;
*
* @return int
*/
abstract public static function getCountOfDefaultAttributes(): int;
abstract public function getCountOfDefaultAttributes(): int;

/**
* Returns number of indexes used by default.
*
* @return int
*/
abstract public static function getCountOfDefaultIndexes(): int;
abstract public function getCountOfDefaultIndexes(): int;

/**
* Get maximum width, in bytes, allowed for a SQL row
* Return 0 when no restrictions apply
*
* @return int
*/
abstract public static function getDocumentSizeLimit(): int;
abstract public function getDocumentSizeLimit(): int;

/**
* Estimate maximum number of bytes required to store a document in $collection.
Expand Down
2 changes: 2 additions & 0 deletions src/Database/Adapter/MariaDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -2312,6 +2312,8 @@ public function setTimeout(int $milliseconds, string $event = Database::EVENT_AL
throw new DatabaseException('Timeout must be greater than 0');
}

$this->timeout = $milliseconds;

$seconds = $milliseconds / 1000;

$this->before($event, 'timeout', function ($sql) use ($seconds) {
Expand Down
3 changes: 3 additions & 0 deletions src/Database/Adapter/MySQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public function setTimeout(int $milliseconds, string $event = Database::EVENT_AL
if ($milliseconds <= 0) {
throw new DatabaseException('Timeout must be greater than 0');
}

$this->timeout = $milliseconds;

$this->before($event, 'timeout', function ($sql) use ($milliseconds) {
return \preg_replace(
pattern: '/SELECT/',
Expand Down
Loading