- Add In/InArray support - Add ORDER BY support for `Find` functions - Update dependencies - Implement fixes identified via static analysis Reviewed-on: #5
66 lines
2.3 KiB
PHP
66 lines
2.3 KiB
PHP
<?php
|
|
/**
|
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
|
* @license MIT
|
|
*/
|
|
|
|
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, $docId), Parameters::id($docId));
|
|
}
|
|
|
|
/**
|
|
* Delete documents by matching a comparison on JSON fields
|
|
*
|
|
* @param string $tableName The table from which documents should be deleted
|
|
* @param Field[] $fields The field comparison to match
|
|
* @param FieldMatch|null $match How to handle multiple conditions (optional; defaults to All)
|
|
* @throws DocumentException If any is encountered
|
|
*/
|
|
public static function byFields(string $tableName, array $fields, ?FieldMatch $match = null): void
|
|
{
|
|
Parameters::nameFields($fields);
|
|
Custom::nonQuery(Query\Delete::byFields($tableName, $fields, $match), Parameters::addFields($fields, []));
|
|
}
|
|
|
|
/**
|
|
* Delete documents matching a JSON containment query (`@>`; PostgreSQL only)
|
|
*
|
|
* @param string $tableName The table from which documents should be deleted
|
|
* @param mixed[]|object $criteria The JSON containment query values
|
|
* @throws DocumentException If the database mode is not PostgreSQL, or if an error occurs
|
|
*/
|
|
public static function byContains(string $tableName, array|object $criteria): void
|
|
{
|
|
Custom::nonQuery(Query\Delete::byContains($tableName), Parameters::json(':criteria', $criteria));
|
|
}
|
|
|
|
/**
|
|
* Delete documents matching a JSON Path match query (`@?`; PostgreSQL only)
|
|
*
|
|
* @param string $tableName The table from which documents should be deleted
|
|
* @param string $path The JSON Path match string
|
|
* @throws DocumentException If the database mode is not PostgreSQL, or if an error occurs
|
|
*/
|
|
public static function byJsonPath(string $tableName, string $path): void
|
|
{
|
|
Custom::nonQuery(Query\Delete::byJsonPath($tableName), [':path' => $path]);
|
|
}
|
|
}
|