-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CTE support to select in QueryBuilder
- Loading branch information
Showing
9 changed files
with
296 additions
and
1 deletion.
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
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
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\DBAL\Query; | ||
|
||
/** @internal */ | ||
final class With | ||
{ | ||
/** @param string[] $columns */ | ||
public function __construct( | ||
public readonly string $name, | ||
public readonly string|QueryBuilder $query, | ||
public readonly array $columns = [], | ||
) { | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\DBAL\SQL\Builder; | ||
|
||
use Doctrine\DBAL\Query\With; | ||
|
||
use function array_map; | ||
use function count; | ||
use function implode; | ||
use function sprintf; | ||
|
||
final class WithSQLBuilder | ||
{ | ||
public function buildSQL(With ...$withParts): string | ||
{ | ||
$parts = array_map( | ||
static fn (With $part) => sprintf( | ||
'%s%s AS (%s)', | ||
$part->name, | ||
self::columns($part->columns), | ||
$part->query, | ||
), | ||
$withParts, | ||
); | ||
|
||
return 'WITH ' . implode(', ', $parts); | ||
} | ||
|
||
/** @param string[] $columns */ | ||
private static function columns(array $columns): string | ||
{ | ||
return count($columns) > 0 ? '(' . implode(', ', $columns) . ')' : ''; | ||
} | ||
} |
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
Oops, something went wrong.