| @@ 35-64 (lines=30) @@ | ||
| 32 | use Repo2\QueryBuilder\ExpressionBag; |
|
| 33 | use Repo2\QueryBuilder\ExpressionInterface; |
|
| 34 | ||
| 35 | class CreateTable implements ExpressionInterface |
|
| 36 | { |
|
| 37 | /** @var Reference */ |
|
| 38 | private $table; |
|
| 39 | ||
| 40 | /** @var ExpressionBag */ |
|
| 41 | private $columnsBag; |
|
| 42 | ||
| 43 | /** |
|
| 44 | * @param Reference $table |
|
| 45 | * @param ExpressionBag $columnsBag |
|
| 46 | */ |
|
| 47 | public function __construct(Reference $table, ExpressionBag $columnsBag) |
|
| 48 | { |
|
| 49 | $this->table = $table; |
|
| 50 | $this->columnsBag = $columnsBag; |
|
| 51 | } |
|
| 52 | ||
| 53 | /** |
|
| 54 | * @inheritDoc |
|
| 55 | */ |
|
| 56 | public function compile(DriverInterface $driver) |
|
| 57 | { |
|
| 58 | if ($this->columnsBag->isEmpty()) { |
|
| 59 | throw new CompileException('The table definition requires columns list.'); |
|
| 60 | } |
|
| 61 | return 'CREATE TABLE ' . $this->table->compile($driver) |
|
| 62 | . '(' . $this->columnsBag->concat($driver, ', ') . ')'; |
|
| 63 | } |
|
| 64 | } |
|
| 65 | ||
| @@ 34-63 (lines=30) @@ | ||
| 31 | use Repo2\QueryBuilder\Expression\Reference; |
|
| 32 | use Repo2\QueryBuilder\ExpressionBag; |
|
| 33 | ||
| 34 | class SelectQuery extends FilterQuery |
|
| 35 | { |
|
| 36 | /** @var Reference */ |
|
| 37 | private $table; |
|
| 38 | ||
| 39 | /** @var ExpressionBag */ |
|
| 40 | private $columnsBag; |
|
| 41 | ||
| 42 | /** |
|
| 43 | * @param Reference $table |
|
| 44 | * @param ExpressionBag $columnsBag |
|
| 45 | */ |
|
| 46 | public function __construct(Reference $table, ExpressionBag $columnsBag) |
|
| 47 | { |
|
| 48 | $this->table = $table; |
|
| 49 | $this->columnsBag = $columnsBag; |
|
| 50 | } |
|
| 51 | ||
| 52 | /** |
|
| 53 | * @inheritDoc |
|
| 54 | */ |
|
| 55 | protected function compileBase(DriverInterface $driver) |
|
| 56 | { |
|
| 57 | if ($this->columnsBag->isEmpty()) { |
|
| 58 | throw new CompileException('Select query requires columns list.'); |
|
| 59 | } |
|
| 60 | return 'SELECT ' . $this->columnsBag->concat($driver, ', ') |
|
| 61 | . ' FROM ' . $this->table->compile($driver); |
|
| 62 | } |
|
| 63 | } |
|
| 64 | ||
| @@ 34-63 (lines=30) @@ | ||
| 31 | use Repo2\QueryBuilder\ExpressionBag; |
|
| 32 | use Repo2\QueryBuilder\Exception\CompileException; |
|
| 33 | ||
| 34 | class UpdateQuery extends FilterQuery |
|
| 35 | { |
|
| 36 | /** @var Reference */ |
|
| 37 | private $table; |
|
| 38 | ||
| 39 | /** @var ExpressionBag */ |
|
| 40 | private $valuesBag; |
|
| 41 | ||
| 42 | /** |
|
| 43 | * @param Reference $table |
|
| 44 | * @param ExpressionBag $valuesBag |
|
| 45 | */ |
|
| 46 | public function __construct(Reference $table, ExpressionBag $valuesBag) |
|
| 47 | { |
|
| 48 | $this->table = $table; |
|
| 49 | $this->valuesBag = $valuesBag; |
|
| 50 | } |
|
| 51 | ||
| 52 | /** |
|
| 53 | * @inheritDoc |
|
| 54 | */ |
|
| 55 | protected function compileBase(DriverInterface $driver) |
|
| 56 | { |
|
| 57 | if ($this->valuesBag->isEmpty()) { |
|
| 58 | throw new CompileException('No values found for update query.'); |
|
| 59 | } |
|
| 60 | return 'UPDATE ' . $this->table->compile($driver) |
|
| 61 | . ' SET ' . $this->valuesBag->concat($driver, ', '); |
|
| 62 | } |
|
| 63 | } |
|
| 64 | ||