Initial SQLite development #1

Merged
danieljsummers merged 25 commits from develop into main 2024-06-08 23:58:45 +00:00
Showing only changes of commit 7390ae0f61 - Show all commits

View File

@ -71,12 +71,20 @@ class Custom
* @param string $query The query to be executed (will have "LIMIT 1" appended) * @param string $query The query to be executed (will have "LIMIT 1" appended)
* @param array $parameters Parameters to use in executing the query * @param array $parameters Parameters to use in executing the query
* @param Mapper<TDoc> $mapper Mapper to deserialize the result * @param Mapper<TDoc> $mapper Mapper to deserialize the result
* @param PDO|null $pdo The database connection to use (optional; will obtain one if not provided)
* @return false|TDoc The item if it is found, false if not * @return false|TDoc The item if it is found, false if not
* @throws DocumentException If any is encountered * @throws DocumentException If any is encountered
*/ */
public static function single(string $query, array $parameters, Mapper $mapper): mixed public static function single(string $query, array $parameters, Mapper $mapper, ?PDO $pdo = null): mixed
{ {
return empty($results = self::array("$query LIMIT 1", $parameters, $mapper)) ? false : $results[0]; try {
$stmt = self::runQuery("$query LIMIT 1", $parameters,
is_null($pdo) ? $actualPDO = Configuration::dbConn() : $pdo);
return ($first = $stmt->fetch(PDO::FETCH_ASSOC)) ? $mapper->map($first) : false;
} finally {
$stmt = null;
if (isset($actualPDO)) $actualPDO = null;
}
} }
/** /**