Initial SQLite development (#1)
Reviewed-on: #1
This commit was merged in pull request #1.
This commit is contained in:
39
src/Count.php
Normal file
39
src/Count.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace BitBadger\PDODocument;
|
||||
|
||||
use BitBadger\PDODocument\Mapper\CountMapper;
|
||||
|
||||
/**
|
||||
* Functions to count documents
|
||||
*/
|
||||
class Count
|
||||
{
|
||||
/**
|
||||
* Count all documents in a table
|
||||
*
|
||||
* @param string $tableName The name of the table in which documents should be counted
|
||||
* @return int The count of documents in the table
|
||||
* @throws DocumentException If one is encountered
|
||||
*/
|
||||
public static function all(string $tableName): int
|
||||
{
|
||||
return Custom::scalar(Query\Count::all($tableName), [], new CountMapper());
|
||||
}
|
||||
|
||||
/**
|
||||
* Count matching documents using a comparison on JSON fields
|
||||
*
|
||||
* @param string $tableName The name of the table in which documents should be counted
|
||||
* @param array|Field[] $fields The field comparison to match
|
||||
* @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, string $conjunction = 'AND'): int
|
||||
{
|
||||
$namedFields = Parameters::nameFields($fields);
|
||||
return Custom::scalar(Query\Count::byFields($tableName, $namedFields, $conjunction),
|
||||
Parameters::addFields($namedFields, []), new CountMapper());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user