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

@@ -13,12 +13,13 @@ class Find
* Query to retrieve a document by its ID
*
* @param string $tableName The name of the table from which a document should be retrieved
* @param mixed $docId The ID of the document to be retrieved (optional; string ID assumed)
* @return string The SELECT statement to retrieve a document by its ID
* @throws DocumentException If the database mode has not been set
*/
public static function byId(string $tableName): string
public static function byId(string $tableName, mixed $docId = null): string
{
return Query::selectFromTable($tableName) . ' WHERE ' . Query::whereById();
return Query::selectFromTable($tableName) . ' WHERE ' . Query::whereById(docId: $docId);
}
/**
@@ -34,4 +35,28 @@ class Find
{
return Query::selectFromTable($tableName) . ' WHERE ' . Query::whereByFields($fields, $match);
}
/**
* Query to retrieve documents using a JSON containment query (PostgreSQL only)
*
* @param string $tableName The name of the table from which documents should be retrieved
* @return string The SELECT statement to retrieve documents by a JSON containment query
* @throws DocumentException If the database mode is not PostgreSQL
*/
public static function byContains(string $tableName): string
{
return Query::selectFromTable($tableName) . ' WHERE ' . Query::whereDataContains();
}
/**
* Query to retrieve documents using a JSON Path match query (PostgreSQL only)
*
* @param string $tableName The name of the table from which documents should be retrieved
* @return string The SELECT statement to retrieve documents by a JSON Path match
* @throws DocumentException If the database mode is not PostgreSQL
*/
public static function byJsonPath(string $tableName): string
{
return Query::selectFromTable($tableName) . ' WHERE ' . Query::whereJsonPathMatches();
}
}