Changes for beta10 (#5)
- Add In/InArray support - Add ORDER BY support for `Find` functions - Update dependencies - Implement fixes identified via static analysis Reviewed-on: #5
This commit was merged in pull request #5.
This commit is contained in:
62
src/Find.php
62
src/Find.php
@@ -22,12 +22,14 @@ class Find
|
||||
* @template TDoc The type of document to be retrieved
|
||||
* @param string $tableName The table from which documents should be retrieved
|
||||
* @param class-string<TDoc> $className The name of the class to be retrieved
|
||||
* @param Field[] $orderBy Fields by which the results should be ordered (optional, default no ordering)
|
||||
* @return DocumentList<TDoc> A list of all documents from the table
|
||||
* @throws DocumentException If any is encountered
|
||||
*/
|
||||
public static function all(string $tableName, string $className): DocumentList
|
||||
public static function all(string $tableName, string $className, array $orderBy = []): DocumentList
|
||||
{
|
||||
return Custom::list(Query::selectFromTable($tableName), [], new DocumentMapper($className));
|
||||
return Custom::list(Query::selectFromTable($tableName) . Query::orderBy($orderBy), [],
|
||||
new DocumentMapper($className));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -51,18 +53,19 @@ class Find
|
||||
*
|
||||
* @template TDoc The type of document to be retrieved
|
||||
* @param string $tableName The table from which documents should be retrieved
|
||||
* @param array|Field[] $fields The field comparison to match
|
||||
* @param Field[] $fields The field comparison to match
|
||||
* @param class-string<TDoc> $className The name of the class to be retrieved
|
||||
* @param FieldMatch|null $match How to handle multiple conditions (optional; defaults to All)
|
||||
* @param Field[] $orderBy Fields by which the results should be ordered (optional, default no ordering)
|
||||
* @return DocumentList<TDoc> A list of documents matching the given field comparison
|
||||
* @throws DocumentException If any is encountered
|
||||
*/
|
||||
public static function byFields(string $tableName, array $fields, string $className,
|
||||
?FieldMatch $match = null): DocumentList
|
||||
?FieldMatch $match = null, array $orderBy = []): DocumentList
|
||||
{
|
||||
$namedFields = Parameters::nameFields($fields);
|
||||
return Custom::list(Query\Find::byFields($tableName, $namedFields, $match),
|
||||
Parameters::addFields($namedFields, []), new DocumentMapper($className));
|
||||
Parameters::nameFields($fields);
|
||||
return Custom::list(Query\Find::byFields($tableName, $fields, $match) . Query::orderBy($orderBy),
|
||||
Parameters::addFields($fields, []), new DocumentMapper($className));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,15 +73,17 @@ class Find
|
||||
*
|
||||
* @template TDoc The type of document to be retrieved
|
||||
* @param string $tableName The name of the table from which documents should be retrieved
|
||||
* @param array|object $criteria The criteria for the JSON containment query
|
||||
* @param mixed[]|object $criteria The criteria for the JSON containment query
|
||||
* @param class-string<TDoc> $className The name of the class to be retrieved
|
||||
* @param Field[] $orderBy Fields by which the results should be ordered (optional, default no ordering)
|
||||
* @return DocumentList<TDoc> A list of documents matching the JSON containment query
|
||||
* @throws DocumentException If the database mode is not PostgreSQL, or if an error occurs
|
||||
*/
|
||||
public static function byContains(string $tableName, array|object $criteria, string $className): DocumentList
|
||||
public static function byContains(string $tableName, array|object $criteria, string $className,
|
||||
array $orderBy = []): DocumentList
|
||||
{
|
||||
return Custom::list(Query\Find::byContains($tableName), Parameters::json(':criteria', $criteria),
|
||||
new DocumentMapper($className));
|
||||
return Custom::list(Query\Find::byContains($tableName) . Query::orderBy($orderBy),
|
||||
Parameters::json(':criteria', $criteria), new DocumentMapper($className));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -88,12 +93,15 @@ class Find
|
||||
* @param string $tableName The name of the table from which documents should be retrieved
|
||||
* @param string $path The JSON Path match string
|
||||
* @param class-string<TDoc> $className The name of the class to be retrieved
|
||||
* @param Field[] $orderBy Fields by which the results should be ordered (optional, default no ordering)
|
||||
* @return DocumentList<TDoc> A list of documents matching the JSON Path
|
||||
* @throws DocumentException If the database mode is not PostgreSQL, or if an error occurs
|
||||
*/
|
||||
public static function byJsonPath(string $tableName, string $path, string $className): DocumentList
|
||||
public static function byJsonPath(string $tableName, string $path, string $className,
|
||||
array $orderBy = []): DocumentList
|
||||
{
|
||||
return Custom::list(Query\Find::byJsonPath($tableName), [':path' => $path], new DocumentMapper($className));
|
||||
return Custom::list(Query\Find::byJsonPath($tableName) . Query::orderBy($orderBy), [':path' => $path],
|
||||
new DocumentMapper($className));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -101,18 +109,19 @@ class Find
|
||||
*
|
||||
* @template TDoc The type of document to be retrieved
|
||||
* @param string $tableName The table from which the document should be retrieved
|
||||
* @param array|Field[] $fields The field comparison to match
|
||||
* @param Field[] $fields The field comparison to match
|
||||
* @param class-string<TDoc> $className The name of the class to be retrieved
|
||||
* @param FieldMatch|null $match How to handle multiple conditions (optional; defaults to All)
|
||||
* @param Field[] $orderBy Fields by which the results should be ordered (optional, default no ordering)
|
||||
* @return Option<TDoc> A `Some` instance with the first document if any matches are found, `None` otherwise
|
||||
* @throws DocumentException If any is encountered
|
||||
*/
|
||||
public static function firstByFields(string $tableName, array $fields, string $className,
|
||||
?FieldMatch $match = null): Option
|
||||
?FieldMatch $match = null, array $orderBy = []): Option
|
||||
{
|
||||
$namedFields = Parameters::nameFields($fields);
|
||||
return Custom::single(Query\Find::byFields($tableName, $namedFields, $match),
|
||||
Parameters::addFields($namedFields, []), new DocumentMapper($className));
|
||||
Parameters::nameFields($fields);
|
||||
return Custom::single(Query\Find::byFields($tableName, $fields, $match) . Query::orderBy($orderBy),
|
||||
Parameters::addFields($fields, []), new DocumentMapper($className));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -120,15 +129,17 @@ class Find
|
||||
*
|
||||
* @template TDoc The type of document to be retrieved
|
||||
* @param string $tableName The name of the table from which documents should be retrieved
|
||||
* @param array|object $criteria The criteria for the JSON containment query
|
||||
* @param mixed[]|object $criteria The criteria for the JSON containment query
|
||||
* @param class-string<TDoc> $className The name of the class to be retrieved
|
||||
* @param Field[] $orderBy Fields by which the results should be ordered (optional, default no ordering)
|
||||
* @return Option<TDoc> A `Some` instance with the first document if any matches are found, `None` otherwise
|
||||
* @throws DocumentException If the database mode is not PostgreSQL, or if an error occurs
|
||||
*/
|
||||
public static function firstByContains(string $tableName, array|object $criteria, string $className): Option
|
||||
public static function firstByContains(string $tableName, array|object $criteria, string $className,
|
||||
array $orderBy = []): Option
|
||||
{
|
||||
return Custom::single(Query\Find::byContains($tableName), Parameters::json(':criteria', $criteria),
|
||||
new DocumentMapper($className));
|
||||
return Custom::single(Query\Find::byContains($tableName) . Query::orderBy($orderBy),
|
||||
Parameters::json(':criteria', $criteria), new DocumentMapper($className));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -138,11 +149,14 @@ class Find
|
||||
* @param string $tableName The name of the table from which documents should be retrieved
|
||||
* @param string $path The JSON Path match string
|
||||
* @param class-string<TDoc> $className The name of the class to be retrieved
|
||||
* @param Field[] $orderBy Fields by which the results should be ordered (optional, default no ordering)
|
||||
* @return Option<TDoc> A `Some` instance with the first document if any matches are found, `None` otherwise
|
||||
* @throws DocumentException If the database mode is not PostgreSQL, or if an error occurs
|
||||
*/
|
||||
public static function firstByJsonPath(string $tableName, string $path, string $className): Option
|
||||
public static function firstByJsonPath(string $tableName, string $path, string $className,
|
||||
array $orderBy = []): Option
|
||||
{
|
||||
return Custom::single(Query\Find::byJsonPath($tableName), [':path' => $path], new DocumentMapper($className));
|
||||
return Custom::single(Query\Find::byJsonPath($tableName) . Query::orderBy($orderBy), [':path' => $path],
|
||||
new DocumentMapper($className));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user