Initial SQLite development (#1)
Reviewed-on: #1
This commit was merged in pull request #1.
This commit is contained in:
36
src/Delete.php
Normal file
36
src/Delete.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace BitBadger\PDODocument;
|
||||
|
||||
/**
|
||||
* Functions to delete documents
|
||||
*/
|
||||
class Delete
|
||||
{
|
||||
/**
|
||||
* Delete a document by its ID
|
||||
*
|
||||
* @param string $tableName The table from which the document should be deleted
|
||||
* @param mixed $docId The ID of the document to be deleted
|
||||
* @throws DocumentException If any is encountered
|
||||
*/
|
||||
public static function byId(string $tableName, mixed $docId): void
|
||||
{
|
||||
Custom::nonQuery(Query\Delete::byId($tableName), Parameters::id($docId));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete documents by matching a comparison on JSON fields
|
||||
*
|
||||
* @param string $tableName The table from which documents should be deleted
|
||||
* @param array|Field[] $fields The field comparison to match
|
||||
* @param string $conjunction How to handle multiple conditions (optional; defaults to `AND`)
|
||||
* @throws DocumentException If any is encountered
|
||||
*/
|
||||
public static function byFields(string $tableName, array $fields, string $conjunction = 'AND'): void
|
||||
{
|
||||
$namedFields = Parameters::nameFields($fields);
|
||||
Custom::nonQuery(Query\Delete::byFields($tableName, $namedFields, $conjunction),
|
||||
Parameters::addFields($namedFields, []));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user