1
0
Fork 0
mirror of synced 2024-07-04 14:10:33 +12:00

get project db for CLI

This commit is contained in:
Damodar Lohani 2022-10-22 03:08:28 +00:00
parent 5b1f8bb2a4
commit ff6c6003fc

View file

@ -12,6 +12,7 @@ use Utopia\Config\Config;
use Utopia\Database\Database;
use Utopia\Database\Validator\Authorization;
use InfluxDB\Database as InfluxDatabase;
use Utopia\Database\Document;
function getInfluxDB(): InfluxDatabase
{
@ -59,6 +60,29 @@ function getConsoleDB(): Database
return $database;
}
function getProjectDB(Document $project): Database
{
global $register;
$pools = $register->get('pools'); /** @var \Utopia\Pools\Group $pools */
if ($project->isEmpty() || $project->getId() === 'console') {
return getConsoleDB();
}
$dbAdapter = $pools
->get($project->getAttribute('database'))
->pop()
->getResource()
;
$database = new Database($dbAdapter, getCache());
$database->setNamespace('_' . $project->getInternalId());
return $database;
}
function getCache(): Cache
{
global $register;