Add classes and tests from common project

This commit is contained in:
2024-06-03 19:46:39 -04:00
parent e91acee70f
commit 1164dc7cc5
32 changed files with 3175 additions and 0 deletions

36
src/Query/Delete.php Normal file
View File

@@ -0,0 +1,36 @@
<?php declare(strict_types=1);
namespace BitBadger\PDODocument\Query;
use BitBadger\PDODocument\Field;
use BitBadger\PDODocument\Query;
/**
* Queries to delete documents
*/
class Delete
{
/**
* Query to delete a document by its ID
*
* @param string $tableName The name of the table from which a document should be deleted
* @return string The DELETE statement to delete a document by its ID
*/
public static function byId(string $tableName): string
{
return "DELETE FROM $tableName WHERE " . Query::whereById();
}
/**
* Query to delete documents using a comparison on JSON fields
*
* @param string $tableName The name of the table from which documents should be deleted
* @param Field[] $fields The field comparison to match
* @param string $conjunction How to handle multiple conditions (optional; defaults to `AND`)
* @return string The DELETE statement to delete documents via field comparison
*/
public static function byFields(string $tableName, array $fields, string $conjunction = 'AND'): string
{
return "DELETE FROM $tableName WHERE " . Query::whereByFields($fields, $conjunction);
}
}