-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #98 Total count JobExecution matched by query
- Loading branch information
Showing
5 changed files
with
85 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
use Doctrine\DBAL\Connection; | ||
use Doctrine\DBAL\Driver\Result; | ||
use Doctrine\DBAL\Exception as DBALException; | ||
use Doctrine\DBAL\Query\QueryBuilder; | ||
use Doctrine\DBAL\Schema\Comparator; | ||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\DBAL\Types\Types; | ||
|
@@ -147,34 +148,10 @@ public function list(string $jobName): iterable | |
|
||
public function query(Query $query): iterable | ||
{ | ||
$queryParameters = []; | ||
$queryTypes = []; | ||
|
||
$qb = $this->connection->createQueryBuilder(); | ||
$qb->select('*') | ||
->from($this->table); | ||
|
||
$names = $query->jobs(); | ||
if (\count($names) > 0) { | ||
$qb->andWhere($qb->expr()->in('job_name', ':jobNames')); | ||
$queryParameters['jobNames'] = $names; | ||
$queryTypes['jobNames'] = Connection::PARAM_STR_ARRAY; | ||
} | ||
|
||
$ids = $query->ids(); | ||
if (\count($ids) > 0) { | ||
$qb->andWhere($qb->expr()->in('id', ':ids')); | ||
$queryParameters['ids'] = $ids; | ||
$queryTypes['ids'] = Connection::PARAM_STR_ARRAY; | ||
} | ||
|
||
$statuses = $query->statuses(); | ||
if (\count($statuses) > 0) { | ||
$qb->andWhere($qb->expr()->in('status', ':statuses')); | ||
$queryParameters['statuses'] = $statuses; | ||
$queryTypes['statuses'] = Connection::PARAM_INT_ARRAY; | ||
} | ||
|
||
switch ($query->sort()) { | ||
case Query::SORT_BY_START_ASC: | ||
$qb->orderBy('start_time', 'asc'); | ||
|
@@ -193,7 +170,18 @@ public function query(Query $query): iterable | |
$qb->setMaxResults($query->limit()); | ||
$qb->setFirstResult($query->offset()); | ||
|
||
yield from $this->queryList($qb->getSQL(), $queryParameters, $queryTypes); | ||
yield from $this->queryList($qb->getSQL(), ...$this->addWheres($query, $qb)); | ||
} | ||
|
||
public function count(Query $query): int | ||
{ | ||
$qb = $this->connection->createQueryBuilder(); | ||
$qb->select('count(*)') | ||
->from($this->table); | ||
|
||
[$parameters, $types] = $this->addWheres($query, $qb); | ||
|
||
return $this->connection->executeQuery($qb->getSQL(), $parameters, $types)->fetchOne(); | ||
} | ||
|
||
private function getSchema(): Schema | ||
|
@@ -303,6 +291,16 @@ private function queryList(string $query, array $parameters, array $types): Gene | |
$statement->free(); | ||
} | ||
|
||
/** | ||
* @phpstan-param array<string, mixed> $parameters | ||
* @phpstan-param array<string, int|string> $types | ||
*/ | ||
private function queryCount(string $query, array $parameters, array $types): false|int | ||
{ | ||
/** @var Result $statement */ | ||
return $this->connection->executeQuery($query, $parameters, $types)->fetchOne(); | ||
Check failure on line 301 in src/batch-doctrine-dbal/src/DoctrineDBALJobExecutionStorage.php GitHub Actions / PhpStan
Check failure on line 301 in src/batch-doctrine-dbal/src/DoctrineDBALJobExecutionStorage.php GitHub Actions / PhpStan
|
||
} | ||
|
||
/** | ||
* @phpstan-return array<string, mixed> | ||
*/ | ||
|
@@ -325,4 +323,36 @@ private function getNormalizer(): JobExecutionRowNormalizer | |
|
||
return $this->normalizer; | ||
} | ||
|
||
/** | ||
* @return array<array<string|int>> | ||
*/ | ||
private function addWheres(Query $query, QueryBuilder $qb): array | ||
{ | ||
$queryParameters = []; | ||
$queryTypes = []; | ||
|
||
$names = $query->jobs(); | ||
if (count($names) > 0) { | ||
$qb->andWhere($qb->expr()->in('job_name', ':jobNames')); | ||
$queryParameters['jobNames'] = $names; | ||
$queryTypes['jobNames'] = Connection::PARAM_STR_ARRAY; | ||
} | ||
|
||
$ids = $query->ids(); | ||
if (count($ids) > 0) { | ||
$qb->andWhere($qb->expr()->in('id', ':ids')); | ||
$queryParameters['ids'] = $ids; | ||
$queryTypes['ids'] = Connection::PARAM_STR_ARRAY; | ||
} | ||
|
||
$statuses = $query->statuses(); | ||
if (count($statuses) > 0) { | ||
$qb->andWhere($qb->expr()->in('status', ':statuses')); | ||
$queryParameters['statuses'] = $statuses; | ||
$queryTypes['statuses'] = Connection::PARAM_INT_ARRAY; | ||
} | ||
|
||
return [$queryParameters, $queryTypes]; | ||
Check failure on line 356 in src/batch-doctrine-dbal/src/DoctrineDBALJobExecutionStorage.php GitHub Actions / PhpStan
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters