| Code Coverage | ||||||||||
| Lines | Functions and Methods | Classes and Traits | ||||||||
| Total |  | 100.00% | 8 / 8 |  | 100.00% | 8 / 8 | CRAP |  | 100.00% | 1 / 1 | 
| Database |  | 100.00% | 8 / 8 |  | 100.00% | 8 / 8 | 8 |  | 100.00% | 1 / 1 | 
| __construct |  | 100.00% | 1 / 1 |  | 100.00% | 1 / 1 | 1 | |||
| select |  | 100.00% | 1 / 1 |  | 100.00% | 1 / 1 | 1 | |||
| selectOne |  | 100.00% | 1 / 1 |  | 100.00% | 1 / 1 | 1 | |||
| insert |  | 100.00% | 1 / 1 |  | 100.00% | 1 / 1 | 1 | |||
| update |  | 100.00% | 1 / 1 |  | 100.00% | 1 / 1 | 1 | |||
| delete |  | 100.00% | 1 / 1 |  | 100.00% | 1 / 1 | 1 | |||
| getPdo |  | 100.00% | 1 / 1 |  | 100.00% | 1 / 1 | 1 | |||
| getConnection |  | 100.00% | 1 / 1 |  | 100.00% | 1 / 1 | 1 | |||
| 1 | <?php | 
| 2 | |
| 3 | declare(strict_types=1); | 
| 4 | |
| 5 | namespace Engelsystem\Database; | 
| 6 | |
| 7 | use Illuminate\Database\Connection as DatabaseConnection; | 
| 8 | use PDO; | 
| 9 | |
| 10 | class Database | 
| 11 | { | 
| 12 | public function __construct(protected DatabaseConnection $connection) | 
| 13 | { | 
| 14 | } | 
| 15 | |
| 16 | /** | 
| 17 | * Run a select query | 
| 18 | * | 
| 19 | * @return object[] | 
| 20 | */ | 
| 21 | public function select(string $query, array $bindings = []): array | 
| 22 | { | 
| 23 | return $this->connection->select($query, $bindings); | 
| 24 | } | 
| 25 | |
| 26 | /** | 
| 27 | * Run a select query and return only the first result or null if no result is found. | 
| 28 | */ | 
| 29 | public function selectOne(string $query, array $bindings = []): ?object | 
| 30 | { | 
| 31 | return $this->connection->selectOne($query, $bindings); | 
| 32 | } | 
| 33 | |
| 34 | /** | 
| 35 | * Run an insert query | 
| 36 | */ | 
| 37 | public function insert(string $query, array $bindings = []): bool | 
| 38 | { | 
| 39 | return $this->connection->insert($query, $bindings); | 
| 40 | } | 
| 41 | |
| 42 | /** | 
| 43 | * Run an update query | 
| 44 | */ | 
| 45 | public function update(string $query, array $bindings = []): int | 
| 46 | { | 
| 47 | return $this->connection->update($query, $bindings); | 
| 48 | } | 
| 49 | |
| 50 | /** | 
| 51 | * Run a delete query | 
| 52 | */ | 
| 53 | public function delete(string $query, array $bindings = []): int | 
| 54 | { | 
| 55 | return $this->connection->delete($query, $bindings); | 
| 56 | } | 
| 57 | |
| 58 | /** | 
| 59 | * Get the PDO instance | 
| 60 | */ | 
| 61 | public function getPdo(): PDO | 
| 62 | { | 
| 63 | return $this->connection->getPdo(); | 
| 64 | } | 
| 65 | |
| 66 | public function getConnection(): DatabaseConnection | 
| 67 | { | 
| 68 | return $this->connection; | 
| 69 | } | 
| 70 | } |