packages/sql-semantics-mysql/src/Model/Statement/Reference/Column/AliasTarget.php
1<?php
2
3declare(strict_types=1);
4
5namespace SqlSemantics\Platform\MySql\Model\Statement\Reference\Column;
6
7use SqlSemantics\Platform\MySql\Model\Statement\Shape\Field;
8use SqlSemantics\Platform\MySql\Model\Statement\Snapshot;
9
10/**
11 * A name that resolves to an output field of the same query by its alias.
12 *
13 * The reference stays a reference: the aliased expression is not copied to the use position.
14 *
15 * @visibility public
16 * @example Resolving an ORDER BY name to an output alias
17 * $query = (new \SqlSemantics\Platform\MySql\Semantics())->analyze('SELECT 1 AS x ORDER BY x');
18 * $query->facts->scalar($query->statement->orderBy[0]->expression)->resolution->field === $query->field('x') // => true
19 */
20final class AliasTarget implements Resolution
21{
22 use Snapshot;
23
24 /**
25 * @param Field $field The output field the alias names
26 */
27 public function __construct(public readonly Field $field)
28 {
29 }
30}
31