Skip to content

Commit 1fa3645

Browse files
committed
* fix adcffb0 get partial reverted by 2efe6f5 @ setResult() & getUnionQueryResult()
* now will format the raw SQL with two spaces indent @ `getUnionQueryResult()` @ `App\PostsQuery\QueryResult` @ be
1 parent dab3f39 commit 1fa3645

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

be/src/PostsQuery/QueryResult.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use Doctrine\ORM\Query\Parser;
1515
use Doctrine\ORM\Query\ResultSetMapping;
1616
use Doctrine\ORM\QueryBuilder;
17+
use Doctrine\SqlFormatter\NullHighlighter;
18+
use Doctrine\SqlFormatter\SqlFormatter;
1719
use Illuminate\Support\Collection;
1820
use Symfony\Component\DependencyInjection\ParameterBag\ContainerBagInterface;
1921
use Symfony\Component\Stopwatch\Stopwatch;
@@ -118,7 +120,7 @@ public function setResult(
118120
'postsKeyByTypePluralName' => $postsKeyByTypePluralName,
119121
'hasMorePages' => $hasMorePages,
120122
'queryPlan' => $queryPlan
121-
] = $this->getUnionQueryResult($queries, $orderByDesc, $maxResults);
123+
] = $this->getUnionQueryResult($queries, $isOrderByDesc, $maxResults);
122124

123125
$this->threads = $postsKeyByTypePluralName->get('threads', collect());
124126
$this->replies = $postsKeyByTypePluralName->get('replies', collect());
@@ -147,11 +149,11 @@ public function setResult(
147149
* orderByField: mixed
148150
* }
149151
* @param Collection<Helpecr::POST_TYPE, QueryBuilder> $queries
150-
* @param bool $orderByDesc
152+
* @param bool $isOrderByDesc
151153
* @param int $maxResults
152154
* @return array{unionOfQueriesSQL: string, postsKeyByTypePluralName: PostsKeyByTypePluralName, hasMorePages: bool, queryPlan: array}
153155
*/
154-
private function getUnionQueryResult(Collection $queries, bool $orderByDesc, int $maxResults): array
156+
private function getUnionQueryResult(Collection $queries, bool $isOrderByDesc, int $maxResults): array
155157
{
156158
/** @var DBALQueryBuilder $unionOfQueries */
157159
// https://stackoverflow.com/questions/36959801/doctrine-orm-querybuilder-or-dbal-querybuilder
@@ -172,10 +174,10 @@ private function getUnionQueryResult(Collection $queries, bool $orderByDesc, int
172174
$firstQueryFieldAliases = array_flip((new Parser($firstQuery->getQuery()))
173175
->parse()->getResultSetMapping()->scalarMappings);
174176
$unionOfQueries = $unionOfQueries
175-
->addOrderBy($firstQueryFieldAliases['orderByField'], $orderByDesc === true ? 'DESC' : 'ASC')
177+
->addOrderBy($firstQueryFieldAliases['orderByField'], $isOrderByDesc === true ? 'DESC' : 'ASC')
176178
->addOrderBy($firstQueryFieldAliases['postId'])
177179
->setMaxResults($maxResults);
178-
$unionOfQueriesSQL = $unionOfQueries->getSQL();
180+
$unionOfQueriesSQL = (new SqlFormatter(new NullHighlighter()))->format($unionOfQueries->getSQL());
179181

180182
$rsm = new ResultSetMapping();
181183
foreach ($firstQueryFieldAliases as $fieldName => $fieldAlias) {

0 commit comments

Comments
 (0)