Initial SQLite development (#1)
Reviewed-on: #1
This commit was merged in pull request #1.
This commit is contained in:
24
src/Mapper/ExistsMapper.php
Normal file
24
src/Mapper/ExistsMapper.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace BitBadger\PDODocument\Mapper;
|
||||
|
||||
use BitBadger\PDODocument\{Configuration, DocumentException, Mode};
|
||||
|
||||
/**
|
||||
* Map an EXISTS result to a boolean value
|
||||
*/
|
||||
class ExistsMapper implements Mapper
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @throws DocumentException If the database mode has not been set
|
||||
*/
|
||||
public function map(array $result): bool
|
||||
{
|
||||
return match (Configuration::$mode) {
|
||||
Mode::PgSQL => (bool)$result[0],
|
||||
Mode::SQLite => (int)$result[0] > 0,
|
||||
default => throw new DocumentException('Database mode not set; cannot map existence result'),
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user