mirror of
https://github.com/appwrite/appwrite
synced 2026-05-24 09:28:40 +00:00
feat: update php docs
This commit is contained in:
parent
58d8b7e148
commit
4f720c30dd
1 changed files with 26 additions and 26 deletions
|
|
@ -16,43 +16,43 @@ use Utopia\Database\Adapter\MariaDB;
|
||||||
use Utopia\Database\Validator\Authorization;
|
use Utopia\Database\Validator\Authorization;
|
||||||
use Utopia\Cache\Adapter\Redis as RedisCache;
|
use Utopia\Cache\Adapter\Redis as RedisCache;
|
||||||
|
|
||||||
class DatabasePool {
|
class DatabasePool
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
*
|
*
|
||||||
* Array to store mappings from database names to PDOPool instances.
|
* Array to store mappings from database names to PDOPool instances.
|
||||||
*/
|
*/
|
||||||
protected array $pools = [];
|
protected array $pools = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
*
|
*
|
||||||
* Array to store mappings from database names to DSNs
|
* Array to store mappings from database names to DSNs
|
||||||
*/
|
*/
|
||||||
protected array $dsns = [];
|
protected array $dsns = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*
|
*
|
||||||
* The name of the console Database
|
* The name of the console Database
|
||||||
*/
|
*/
|
||||||
protected string $consoleDB = '';
|
protected string $consoleDB = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for Database pools
|
* Constructor for Database pools
|
||||||
*
|
*
|
||||||
* @param array $consoleDB
|
* @param array $consoleDB
|
||||||
* @param array $projectDB
|
* @param array $projectDB
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function __construct(array $consoleDB, array $projectDB)
|
public function __construct(array $consoleDB, array $projectDB)
|
||||||
{
|
{
|
||||||
if(count($consoleDB) != 1) {
|
if (count($consoleDB) != 1) {
|
||||||
throw new Exception('Console DB should contain only one entry', 500);
|
throw new Exception('Console DB should contain only one entry', 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(empty($projectDB)) {
|
if (empty($projectDB)) {
|
||||||
throw new Exception('Project DB is not defined', 500);
|
throw new Exception('Project DB is not defined', 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -87,7 +87,7 @@ class DatabasePool {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to get a PDO instance by database name
|
* Function to get a PDO instance by database name
|
||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @return ?PDO
|
* @return ?PDO
|
||||||
*/
|
*/
|
||||||
|
|
@ -115,10 +115,10 @@ class DatabasePool {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to return the name of the database from the project ID
|
* Function to return the name of the database from the project ID
|
||||||
*
|
*
|
||||||
* @param string $projectID
|
* @param string $projectID
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
private function getName(string $projectID, \Redis $redis): array
|
private function getName(string $projectID, \Redis $redis): array
|
||||||
{
|
{
|
||||||
|
|
@ -135,15 +135,15 @@ class DatabasePool {
|
||||||
$project = Authorization::skip(fn() => $database->getDocument('projects', $projectID));
|
$project = Authorization::skip(fn() => $database->getDocument('projects', $projectID));
|
||||||
$internalID = $project->getInternalId();
|
$internalID = $project->getInternalId();
|
||||||
$database = $project->getAttribute('database', '');
|
$database = $project->getAttribute('database', '');
|
||||||
|
|
||||||
return [$database, $internalID];
|
return [$database, $internalID];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to get a single PDO instance for a project
|
* Function to get a single PDO instance for a project
|
||||||
*
|
*
|
||||||
* @param string $projectId
|
* @param string $projectId
|
||||||
*
|
*
|
||||||
* @return ?Database
|
* @return ?Database
|
||||||
*/
|
*/
|
||||||
public function getDB(string $projectID, ?\Redis $redis): ?Database
|
public function getDB(string $projectID, ?\Redis $redis): ?Database
|
||||||
|
|
@ -166,14 +166,14 @@ class DatabasePool {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to get a database instance from a PDO and cache
|
* Function to get a database instance from a PDO and cache
|
||||||
*
|
*
|
||||||
* @param PDO $pdo
|
* @param PDO $pdo
|
||||||
* @param \Redis $redis
|
* @param \Redis $redis
|
||||||
*
|
*
|
||||||
* @return Database
|
* @return Database
|
||||||
*/
|
*/
|
||||||
private function getDatabase(PDO|PDOProxy $pdo, \Redis $redis): Database
|
private function getDatabase(PDO|PDOProxy $pdo, \Redis $redis): Database
|
||||||
{
|
{
|
||||||
$cache = new Cache(new RedisCache($redis));
|
$cache = new Cache(new RedisCache($redis));
|
||||||
$database = new Database(new MariaDB($pdo), $cache);
|
$database = new Database(new MariaDB($pdo), $cache);
|
||||||
|
|
@ -182,9 +182,9 @@ class DatabasePool {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to get a PDO instance from the list of available database pools. Meant to be used in co-routines
|
* Function to get a PDO instance from the list of available database pools. Meant to be used in co-routines
|
||||||
*
|
*
|
||||||
* @param string $projectId
|
* @param string $projectId
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getDBFromPool(string $projectID, \Redis $redis): array
|
public function getDBFromPool(string $projectID, \Redis $redis): array
|
||||||
|
|
@ -192,7 +192,7 @@ class DatabasePool {
|
||||||
/** Get DB name from the console database */
|
/** Get DB name from the console database */
|
||||||
[$name, $internalID] = $this->getName($projectID, $redis);
|
[$name, $internalID] = $this->getName($projectID, $redis);
|
||||||
$pool = $this->pools[$name] ?? throw new Exception("Database pool with name : $name not found. Check the value of _APP_PROJECT_DB in .env", 500);
|
$pool = $this->pools[$name] ?? throw new Exception("Database pool with name : $name not found. Check the value of _APP_PROJECT_DB in .env", 500);
|
||||||
|
|
||||||
$namespace = "_$internalID";
|
$namespace = "_$internalID";
|
||||||
$attempts = 0;
|
$attempts = 0;
|
||||||
do {
|
do {
|
||||||
|
|
@ -226,7 +226,7 @@ class DatabasePool {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to get a random PDO instance from the available database pools
|
* Function to get a random PDO instance from the available database pools
|
||||||
*
|
*
|
||||||
* @return array [PDO, string]
|
* @return array [PDO, string]
|
||||||
*/
|
*/
|
||||||
public function getAnyFromPool(\Redis $redis): array
|
public function getAnyFromPool(\Redis $redis): array
|
||||||
|
|
@ -269,7 +269,7 @@ class DatabasePool {
|
||||||
*
|
*
|
||||||
* @param PDOProxy $db
|
* @param PDOProxy $db
|
||||||
* @param string $name
|
* @param string $name
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function put(PDOProxy $db, string $name): void
|
public function put(PDOProxy $db, string $name): void
|
||||||
|
|
@ -283,7 +283,7 @@ class DatabasePool {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to get the name of the console DB
|
* Function to get the name of the console DB
|
||||||
*
|
*
|
||||||
* @return ?string
|
* @return ?string
|
||||||
*/
|
*/
|
||||||
public function getConsoleDB(): ?string
|
public function getConsoleDB(): ?string
|
||||||
|
|
@ -294,4 +294,4 @@ class DatabasePool {
|
||||||
|
|
||||||
return $this->consoleDB;
|
return $this->consoleDB;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue