Use PDO singleton

This commit is contained in:
2024-06-07 20:57:12 -04:00
parent bcca9f5ace
commit d9ffc36fe6
10 changed files with 61 additions and 95 deletions

View File

@@ -3,7 +3,6 @@
namespace BitBadger\PDODocument;
use BitBadger\PDODocument\Mapper\CountMapper;
use PDO;
/**
* Functions to count documents
@@ -14,13 +13,12 @@ class Count
* Count all documents in a table
*
* @param string $tableName The name of the table in which documents should be counted
* @param PDO|null $pdo The database connection to use (optional; will obtain one if not provided)
* @return int The count of documents in the table
* @throws DocumentException If one is encountered
*/
public static function all(string $tableName, ?PDO $pdo = null): int
public static function all(string $tableName): int
{
return Custom::scalar(Query\Count::all($tableName), [], new CountMapper(), $pdo);
return Custom::scalar(Query\Count::all($tableName), [], new CountMapper());
}
/**
@@ -28,16 +26,14 @@ class Count
*
* @param string $tableName The name of the table in which documents should be counted
* @param array|Field[] $fields The field comparison to match
* @param PDO|null $pdo The database connection to use (optional; will obtain one if not provided)
* @param string $conjunction How to handle multiple conditions (optional; defaults to `AND`)
* @return int The count of documents matching the field comparison
* @throws DocumentException If one is encountered
*/
public static function byFields(string $tableName, array $fields, ?PDO $pdo = null,
string $conjunction = 'AND'): int
public static function byFields(string $tableName, array $fields, string $conjunction = 'AND'): int
{
$namedFields = Parameters::nameFields($fields);
return Custom::scalar(Query\Count::byFields($tableName, $namedFields, $conjunction),
Parameters::addFields($namedFields, []), new CountMapper(), $pdo);
Parameters::addFields($namedFields, []), new CountMapper());
}
}