packages/ztd-query-core/src/Platform/CastRenderer.php
1<?php
2
3declare(strict_types=1);
4
5namespace ZtdQuery\Platform;
6
7use ZtdQuery\Schema\ColumnDeclaration;
8
9/**
10 * Renders platform-specific CAST expressions.
11 *
12 * Each platform provides an implementation that maps ColumnDeclaration
13 * to the appropriate CAST syntax for that SQL dialect.
14 */
15interface CastRenderer
16{
17 /**
18 * Render a CAST expression for a given expression string.
19 *
20 * @param string $expression The SQL expression to cast (e.g. "'Alice'", "1", "NULL").
21 * @param ColumnDeclaration $type The target column type.
22 * @return string A SQL CAST expression (e.g. "CAST('Alice' AS CHAR)").
23 */
24 public function renderCast(string $expression, ColumnDeclaration $type): string;
25
26 /**
27 * Render a CAST expression for NULL with the given type.
28 *
29 * Used for empty CTE definitions to preserve column type information.
30 *
31 * @param ColumnDeclaration $type The target column type.
32 * @return string A SQL CAST(NULL AS ...) expression.
33 */
34 public function renderNullCast(ColumnDeclaration $type): string;
35}
36