|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright 2021 Aleksandar Panic |
|
4
|
|
|
* |
|
5
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
6
|
|
|
* you may not use this file except in compliance with the License. |
|
7
|
|
|
* You may obtain a copy of the License at |
|
8
|
|
|
* |
|
9
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
10
|
|
|
* |
|
11
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
12
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
13
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14
|
|
|
* See the License for the specific language governing permissions and |
|
15
|
|
|
* limitations under the License. |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
namespace ArekX\PQL\Drivers\MySql\Builder; |
|
19
|
|
|
|
|
20
|
|
|
use ArekX\PQL\Contracts\QueryBuilder; |
|
21
|
|
|
use ArekX\PQL\Contracts\QueryBuilderState; |
|
22
|
|
|
use ArekX\PQL\Drivers\MySql\Builder\Builders\DeleteBuilder; |
|
23
|
|
|
use ArekX\PQL\Drivers\MySql\Builder\Builders\QueryPartBuilder; |
|
24
|
|
|
use ArekX\PQL\Sql\Query\Delete; |
|
25
|
|
|
use ArekX\PQL\Sql\SqlParamBuilder; |
|
26
|
|
|
use ArekX\PQL\Sql\SqlQueryBuilderFactory; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Represents a query builder for MySQL |
|
30
|
|
|
*/ |
|
31
|
|
|
class MySqlQueryBuilder extends SqlQueryBuilderFactory |
|
32
|
|
|
{ |
|
33
|
|
|
const BUILDERS = [ |
|
34
|
|
|
Delete::class => DeleteBuilder::class |
|
35
|
|
|
]; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @inheritDoc |
|
39
|
|
|
*/ |
|
40
|
3 |
|
protected function createBuilder(string $queryClass): QueryBuilder |
|
41
|
|
|
{ |
|
42
|
3 |
|
if (empty(self::BUILDERS[$queryClass])) { |
|
43
|
1 |
|
throw new \Exception('No builder defined for: ' . $queryClass); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** @var QueryPartBuilder $builderClass */ |
|
47
|
2 |
|
$builderClass = self::BUILDERS[$queryClass]; |
|
48
|
|
|
|
|
49
|
2 |
|
return new $builderClass(); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @inheritDoc |
|
54
|
|
|
*/ |
|
55
|
2 |
|
protected function createState(): QueryBuilderState |
|
56
|
|
|
{ |
|
57
|
2 |
|
$state = MySqlQueryBuilderState::create(); |
|
58
|
|
|
|
|
59
|
2 |
|
$state->set('paramsBuilder', SqlParamBuilder::create()); |
|
60
|
2 |
|
$state->set('parentBuilder', $this); |
|
61
|
|
|
|
|
62
|
2 |
|
return $state; |
|
63
|
|
|
} |
|
64
|
|
|
} |