Files
pdo-document/src/Mapper/ExistsMapper.php

33 lines
674 B
PHP
Raw Normal View History

<?php
/**
* @author Daniel J. Summers <daniel@bitbadger.solutions>
* @license MIT
*/
declare(strict_types=1);
namespace BitBadger\PDODocument\Mapper;
use BitBadger\PDODocument\{Configuration, Mode};
use Exception;
/**
* Map an EXISTS result to a boolean value
*
* @implements Mapper<bool>
*/
class ExistsMapper implements Mapper
{
/**
* @inheritDoc
* @throws Exception If the database mode has not been set
*/
public function map(array $result): bool
{
return match (Configuration::mode('map existence result')) {
Mode::PgSQL => (bool)$result[0],
2024-07-21 22:02:16 -04:00
Mode::SQLite => (int)$result[0] > 0,
};
}
}