Skip to content

Commit 63083ec

Browse files
committed
Add PDO proxy
1 parent 00ad886 commit 63083ec

File tree

12 files changed

+48
-9
lines changed

12 files changed

+48
-9
lines changed

bin/tasks/index.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Utopia\Database\Adapter\Mongo;
1414
use Utopia\Database\Adapter\MySQL;
1515
use Utopia\Database\Database;
16+
use Utopia\Database\PDO;
1617
use Utopia\Mongo\Client;
1718
use Utopia\Validator\Text;
1819

bin/tasks/load.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Utopia\Database\Document;
2121
use Utopia\Database\Helpers\Permission;
2222
use Utopia\Database\Helpers\Role;
23+
use Utopia\Database\PDO;
2324
use Utopia\Database\Validator\Authorization;
2425
use Utopia\Mongo\Client;
2526
use Utopia\Validator\Numeric;

src/Database/PDO.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace Utopia\Database;
4+
5+
class PDO
6+
{
7+
protected \PDO $pdo;
8+
9+
public function __construct(
10+
protected string $dsn,
11+
protected ?string $username,
12+
protected ?string $password,
13+
protected array $config = []
14+
) {
15+
$this->pdo = new \PDO(
16+
$this->dsn,
17+
$this->username,
18+
$this->password,
19+
$this->config
20+
);
21+
}
22+
23+
public function __call(string $method, array $args): mixed
24+
{
25+
return $this->pdo->{$method}(...$args);
26+
}
27+
28+
public function reconnect(): void
29+
{
30+
$this->pdo = new \PDO(
31+
$this->dsn,
32+
$this->username,
33+
$this->password,
34+
$this->config
35+
);
36+
}
37+
}

tests/e2e/Adapter/MariaDBTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
namespace Tests\E2E\Adapter;
44

5-
use PDO;
65
use Redis;
76
use Utopia\Cache\Adapter\Redis as RedisAdapter;
87
use Utopia\Cache\Cache;
98
use Utopia\Database\Adapter\MariaDB;
109
use Utopia\Database\Database;
10+
use Utopia\Database\PDO;
1111

1212
class MariaDBTest extends Base
1313
{

tests/e2e/Adapter/MirrorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Tests\E2E\Adapter;
44

5-
use PDO;
65
use Redis;
76
use Utopia\Cache\Adapter\Redis as RedisAdapter;
87
use Utopia\Cache\Cache;
@@ -18,6 +17,7 @@
1817
use Utopia\Database\Helpers\Permission;
1918
use Utopia\Database\Helpers\Role;
2019
use Utopia\Database\Mirror;
20+
use Utopia\Database\PDO;
2121

2222
class MirrorTest extends Base
2323
{

tests/e2e/Adapter/MySQLTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
namespace Tests\E2E\Adapter;
44

5-
use PDO;
65
use Redis;
76
use Utopia\Cache\Adapter\Redis as RedisAdapter;
87
use Utopia\Cache\Cache;
98
use Utopia\Database\Adapter\MySQL;
109
use Utopia\Database\Database;
10+
use Utopia\Database\PDO;
1111

1212
class MySQLTest extends Base
1313
{

tests/e2e/Adapter/PostgresTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
namespace Tests\E2E\Adapter;
44

5-
use PDO;
65
use Redis;
76
use Utopia\Cache\Adapter\Redis as RedisAdapter;
87
use Utopia\Cache\Cache;
98
use Utopia\Database\Adapter\Postgres;
109
use Utopia\Database\Database;
10+
use Utopia\Database\PDO;
1111

1212
class PostgresTest extends Base
1313
{

tests/e2e/Adapter/SQLiteTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
namespace Tests\E2E\Adapter;
44

5-
use PDO;
65
use Redis;
76
use Utopia\Cache\Adapter\Redis as RedisAdapter;
87
use Utopia\Cache\Cache;
98
use Utopia\Database\Adapter\SQLite;
109
use Utopia\Database\Database;
10+
use Utopia\Database\PDO;
1111

1212
class SQLiteTest extends Base
1313
{

tests/e2e/Adapter/SharedTables/MariaDBTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
namespace Tests\E2E\Adapter\SharedTables;
44

5-
use PDO;
65
use Redis;
76
use Tests\E2E\Adapter\Base;
87
use Utopia\Cache\Adapter\Redis as RedisAdapter;
98
use Utopia\Cache\Cache;
109
use Utopia\Database\Adapter\MariaDB;
1110
use Utopia\Database\Database;
11+
use Utopia\Database\PDO;
1212

1313
class MariaDBTest extends Base
1414
{

tests/e2e/Adapter/SharedTables/MySQLTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
namespace Tests\E2E\Adapter\SharedTables;
44

5-
use PDO;
65
use Redis;
76
use Tests\E2E\Adapter\Base;
87
use Utopia\Cache\Adapter\Redis as RedisAdapter;
98
use Utopia\Cache\Cache;
109
use Utopia\Database\Adapter\MySQL;
1110
use Utopia\Database\Database;
11+
use Utopia\Database\PDO;
1212

1313
class MySQLTest extends Base
1414
{

0 commit comments

Comments
 (0)