3
namespace Upside\Db\SQL;
7
protected SQLStatement $sql;
9
public function __construct(SQLStatement $statement)
11
$this->sql = $statement;
14
public function __clone()
16
$this->sql = clone $this->sql;
19
public function column(string|\Closure|Expression $name, ?string $alias = null): static
21
$this->sql->add_column($name, $alias);
27
* Add multiple columns at once
29
public function columns(array $columns): static
31
foreach ($columns as $name => $alias) {
32
if (!\is_string($name)) {
33
$this->column($alias, null);
36
if (\is_string($alias)) {
37
$this->column($name, $alias);
39
$this->column($alias, $name);
47
* Add a `COUNT` expression
49
public function count(array|string|Expression $column = '*', ?string $alias = null, bool $distinct = false): static
51
return $this->column((new Expression())->count($column, $distinct), $alias);
55
* Add an `AVG` expression
57
public function avg(string|Expression $column, ?string $alias = null, bool $distinct = false): static
59
return $this->column((new Expression())->avg($column, $distinct), $alias);
63
* Add a `SUM` expression
65
public function sum(string|\Closure|Expression $column, ?string $alias = null, bool $distinct = false): static
67
return $this->column((new Expression())->sum($column, $distinct), $alias);
71
* Add a `MIN` expression
73
public function min(string|Expression $column, ?string $alias = null, bool $distinct = false): static
75
return $this->column((new Expression())->min($column, $distinct), $alias);
79
* Add a `MAX` expression
81
public function max(string|Expression $column, ?string $alias = null, bool $distinct = false): static
83
return $this->column((new Expression())->max($column, $distinct), $alias);
87
* Add a `UCASE` expression
89
public function ucase(string|Expression $column, ?string $alias = null): static
91
return $this->column((new Expression())->ucase($column), $alias);
95
* Add a `LCASE` expression
97
public function lcase(string|Expression $column, ?string $alias = null): static
99
return $this->column((new Expression())->lcase($column), $alias);
103
* Add a `MID` expression
105
* @param string|Expression $column Column
106
* @param int $start (optional) Substring start
107
* @param int $length (optional) Substring length
109
public function mid($column, int $start = 1, ?string $alias = null, int $length = 0): static
111
return $this->column((new Expression())->mid($column, $start, $length), $alias);
115
* Add a `LEN` expression
117
* @param string|Expression $column Column
119
public function len($column, ?string $alias = null): static
121
return $this->column((new Expression())->len($column), $alias);
125
* Add a `FORMAT` expression
127
* @param string|Expression $column Column
129
public function round($column, int $decimals = 0, ?string $alias = null): static
131
return $this->column((new Expression())->format($column, $decimals), $alias);
135
* Add a `FORMAT` expression
137
* @param string|Expression $column Column
139
public function format($column, int $format, ?string $alias = null): static
141
return $this->column((new Expression())->format($column, $format), $alias);
145
* Add a `NOW` expression
147
public function now(?string $alias = null): static
149
return $this->column((new Expression())->now(), $alias);