Initial SQLite development (#1)
Reviewed-on: #1
This commit was merged in pull request #1.
This commit is contained in:
35
src/Query/Count.php
Normal file
35
src/Query/Count.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace BitBadger\PDODocument\Query;
|
||||
|
||||
use BitBadger\PDODocument\{Field, Query};
|
||||
|
||||
/**
|
||||
* Queries for counting documents
|
||||
*/
|
||||
class Count
|
||||
{
|
||||
/**
|
||||
* Query to count all documents in a table
|
||||
*
|
||||
* @param string $tableName The name of the table in which documents should be counted
|
||||
* @return string The query to count all documents in a table
|
||||
*/
|
||||
public static function all(string $tableName): string
|
||||
{
|
||||
return "SELECT COUNT(*) FROM $tableName";
|
||||
}
|
||||
|
||||
/**
|
||||
* Query to count matching documents using a text comparison on JSON fields
|
||||
*
|
||||
* @param string $tableName The name of the table in which documents should be counted
|
||||
* @param Field[] $fields The field comparison to match
|
||||
* @param string $conjunction How to handle multiple conditions (optional; defaults to `AND`)
|
||||
* @return string The query to count documents using a field comparison
|
||||
*/
|
||||
public static function byFields(string $tableName, array $fields, string $conjunction = 'AND'): string
|
||||
{
|
||||
return self::all($tableName) . ' WHERE ' . Query::whereByFields($fields, $conjunction);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user