Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
3 / 3 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| BuilderAbstract | |
100.00% |
3 / 3 |
|
100.00% |
3 / 3 |
3 | |
100.00% |
1 / 1 |
| getConnection | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| quote | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getType | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toSql | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| execute | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| 1 | <?php |
| 2 | /** |
| 3 | * Jingga |
| 4 | * |
| 5 | * PHP Version 8.1 |
| 6 | * |
| 7 | * @package phpOMS\DataStorage\Database |
| 8 | * @copyright Dennis Eichhorn |
| 9 | * @license OMS License 2.0 |
| 10 | * @version 1.0.0 |
| 11 | * @link https://jingga.app |
| 12 | */ |
| 13 | declare(strict_types=1); |
| 14 | |
| 15 | namespace phpOMS\DataStorage\Database; |
| 16 | |
| 17 | use phpOMS\DataStorage\Database\Connection\ConnectionAbstract; |
| 18 | use phpOMS\DataStorage\Database\Query\QueryType; |
| 19 | |
| 20 | /** |
| 21 | * Database query builder. |
| 22 | * |
| 23 | * @package phpOMS\DataStorage\Database |
| 24 | * @license OMS License 2.0 |
| 25 | * @link https://jingga.app |
| 26 | * @since 1.0.0 |
| 27 | */ |
| 28 | abstract class BuilderAbstract |
| 29 | { |
| 30 | /** |
| 31 | * Is read only. |
| 32 | * |
| 33 | * @var bool |
| 34 | * @since 1.0.0 |
| 35 | */ |
| 36 | protected bool $isReadOnly = false; |
| 37 | |
| 38 | /** |
| 39 | * Grammar. |
| 40 | * |
| 41 | * @var GrammarAbstract |
| 42 | * @since 1.0.0 |
| 43 | */ |
| 44 | protected GrammarAbstract $grammar; |
| 45 | |
| 46 | /** |
| 47 | * Database connection. |
| 48 | * |
| 49 | * @var ConnectionAbstract |
| 50 | * @since 1.0.0 |
| 51 | */ |
| 52 | protected ConnectionAbstract $connection; |
| 53 | |
| 54 | /** |
| 55 | * Query type. |
| 56 | * |
| 57 | * @var int |
| 58 | * @since 1.0.0 |
| 59 | */ |
| 60 | protected int $type = QueryType::NONE; |
| 61 | |
| 62 | /** |
| 63 | * Raw. |
| 64 | * |
| 65 | * @var string |
| 66 | * @since 1.0.0 |
| 67 | */ |
| 68 | public string $raw = ''; |
| 69 | |
| 70 | /** |
| 71 | * Get connection |
| 72 | * |
| 73 | * @return ConnectionAbstract |
| 74 | * |
| 75 | * @since 1.0.0 |
| 76 | */ |
| 77 | public function getConnection() : ConnectionAbstract |
| 78 | { |
| 79 | return $this->connection; |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Escape string value |
| 84 | * |
| 85 | * @param string $value Value to escape |
| 86 | * |
| 87 | * @return string |
| 88 | * |
| 89 | * @since 1.0.0 |
| 90 | */ |
| 91 | public function quote(string $value) : string |
| 92 | { |
| 93 | return $this->connection->con->quote($value); |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Get query type. |
| 98 | * |
| 99 | * @return int |
| 100 | * |
| 101 | * @since 1.0.0 |
| 102 | */ |
| 103 | public function getType() : int |
| 104 | { |
| 105 | return $this->type; |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Parsing to sql string. |
| 110 | * |
| 111 | * @return string |
| 112 | * |
| 113 | * @since 1.0.0 |
| 114 | */ |
| 115 | abstract public function toSql() : string; |
| 116 | |
| 117 | /** |
| 118 | * Execute query. |
| 119 | * |
| 120 | * @return ?\PDOStatement |
| 121 | * |
| 122 | * @since 1.0.0 |
| 123 | */ |
| 124 | abstract public function execute() : ?\PDOStatement; |
| 125 | } |