Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
75.00% |
3 / 4 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| SQLiteGrammar | |
75.00% |
3 / 4 |
|
0.00% |
0 / 1 |
2.06 | |
0.00% |
0 / 1 |
| compileRandom | |
75.00% |
3 / 4 |
|
0.00% |
0 / 1 |
2.06 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Jingga |
| 4 | * |
| 5 | * PHP Version 8.1 |
| 6 | * |
| 7 | * @package phpOMS\DataStorage\Database\Query\Grammar |
| 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\Query\Grammar; |
| 16 | |
| 17 | use phpOMS\DataStorage\Database\Query\Builder; |
| 18 | |
| 19 | /** |
| 20 | * Grammar class. |
| 21 | * |
| 22 | * @package phpOMS\DataStorage\Database\Query\Grammar |
| 23 | * @license OMS License 2.0 |
| 24 | * @link https://jingga.app |
| 25 | * @since 1.0.0 |
| 26 | */ |
| 27 | class SQLiteGrammar extends Grammar |
| 28 | { |
| 29 | /** |
| 30 | * System identifier. |
| 31 | * |
| 32 | * @var string |
| 33 | * @since 1.0.0 |
| 34 | */ |
| 35 | public string $systemIdentifierStart = '`'; |
| 36 | |
| 37 | /** |
| 38 | * System identifier. |
| 39 | * |
| 40 | * @var string |
| 41 | * @since 1.0.0 |
| 42 | */ |
| 43 | public string $systemIdentifierEnd = '`'; |
| 44 | |
| 45 | /** |
| 46 | * Compile random. |
| 47 | * |
| 48 | * @param Builder $query Builder |
| 49 | * @param array $columns Columns |
| 50 | * |
| 51 | * @return string |
| 52 | * |
| 53 | * @since 1.0.0 |
| 54 | */ |
| 55 | protected function compileRandom(Builder $query, array $columns) : string |
| 56 | { |
| 57 | $expression = $this->expressionizeTableColumn($columns); |
| 58 | |
| 59 | if ($expression === '') { |
| 60 | $expression = '*'; |
| 61 | } |
| 62 | |
| 63 | return 'SELECT ' . $expression . ' ' . $this->compileFrom($query, $query->from) . ' ORDER BY RANDOM() ' . $this->compileLimit($query, $query->limit ?? 1); |
| 64 | } |
| 65 | } |