Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 20 |
|
0.00% |
0 / 8 |
CRAP | |
0.00% |
0 / 1 |
| QueryExecutor | |
0.00% |
0 / 20 |
|
0.00% |
0 / 8 |
90 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| isTableExist | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| createTable | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| listTables | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| findColumns | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| findAll | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| findAllColumn | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| findAllCount | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Dynart\Micro\Entities; |
| 4 | |
| 5 | class QueryExecutor { |
| 6 | |
| 7 | public function __construct( |
| 8 | protected Database $db, |
| 9 | protected EntityManager $em, |
| 10 | protected QueryBuilder $queryBuilder, |
| 11 | ) {} |
| 12 | |
| 13 | public function isTableExist(string $className): bool { |
| 14 | $result = $this->db->fetchOne($this->queryBuilder->isTableExist(':dbName', ':tableName'), [ |
| 15 | ':dbName' => $this->db->configValue('name'), |
| 16 | ':tableName' => $this->em->tableNameByClass($className) |
| 17 | ]); |
| 18 | return (bool)$result; |
| 19 | } |
| 20 | |
| 21 | public function createTable(string $className, bool $ifNotExists = false): void { |
| 22 | $sql = $this->queryBuilder->createTable($className, $ifNotExists); |
| 23 | $this->db->query($sql); |
| 24 | } |
| 25 | |
| 26 | public function listTables(): array { |
| 27 | $sql = $this->queryBuilder->listTables(); |
| 28 | return $this->db->fetchColumn($sql); |
| 29 | } |
| 30 | |
| 31 | public function findColumns(string $className): array { |
| 32 | $sql = $this->queryBuilder->describeTable($className); |
| 33 | return $this->queryBuilder->columnsByTableDescription($this->db->fetchAll($sql)); |
| 34 | } |
| 35 | |
| 36 | public function findAll(Query $query, array $fields = []): array { |
| 37 | $sql = $this->queryBuilder->findAll($query, $fields); |
| 38 | return $this->db->fetchAll($sql, $query->variables()); |
| 39 | } |
| 40 | |
| 41 | public function findAllColumn(Query $query, string $column = ''): array { |
| 42 | $fields = $column ? [$column] : []; |
| 43 | $sql = $this->queryBuilder->findAll($query, $fields); |
| 44 | return $this->db->fetchColumn($sql, $query->variables()); |
| 45 | } |
| 46 | |
| 47 | public function findAllCount(Query $query): mixed { |
| 48 | $sql = $this->queryBuilder->findAllCount($query); |
| 49 | return $this->db->fetchOne($sql, $query->variables()); |
| 50 | } |
| 51 | } |