Add PostgreSQL Support (#3)

Reviewed-on: #3
This commit was merged in pull request #3.
This commit is contained in:
2024-06-21 13:46:41 +00:00
parent 330e272187
commit 124426fa12
61 changed files with 2290 additions and 223 deletions

View File

@@ -17,7 +17,7 @@ class Patch
*/
public static function byId(string $tableName, mixed $docId, array|object $patch): void
{
Custom::nonQuery(Query\Patch::byId($tableName),
Custom::nonQuery(Query\Patch::byId($tableName, $docId),
array_merge(Parameters::id($docId), Parameters::json(':data', $patch)));
}
@@ -37,4 +37,32 @@ class Patch
Custom::nonQuery(Query\Patch::byFields($tableName, $namedFields, $match),
Parameters::addFields($namedFields, Parameters::json(':data', $patch)));
}
/**
* Patch documents using a JSON containment query (`@>`; PostgreSQL only)
*
* @param string $tableName The table in which documents should be patched
* @param array|object $criteria The JSON containment query values to match
* @param array|object $patch The object with which the documents should be patched (will be JSON-encoded)
* @throws DocumentException If the database mode is not PostgreSQL, or if an error occurs
*/
public static function byContains(string $tableName, array|object $criteria, array|object $patch): void
{
Custom::nonQuery(Query\Patch::byContains($tableName),
array_merge(Parameters::json(':criteria', $criteria), Parameters::json(':data', $patch)));
}
/**
* Patch documents using a JSON Path match query (`@?`; PostgreSQL only)
*
* @param string $tableName The table in which documents should be patched
* @param string $path The JSON Path match string
* @param array|object $patch The object with which the documents should be patched (will be JSON-encoded)
* @throws DocumentException If the database mode is not PostgreSQL, or if an error occurs
*/
public static function byJsonPath(string $tableName, string $path, array|object $patch): void
{
Custom::nonQuery(Query\Patch::byJsonPath($tableName),
array_merge([':path' => $path], Parameters::json(':data', $patch)));
}
}