- Still WIP on Api's wrapper

This commit is contained in:
Dave Mc Nicoll 2023-10-27 18:33:48 -04:00
parent 1927b43999
commit 8e0dce3e71
6 changed files with 26 additions and 6 deletions

View File

@ -68,7 +68,7 @@ abstract class Sql {
return static::identifier($sql);
}
public static function escape($value)
public static function escape($value) : mixed
{
switch(true) {
case is_object($value):

View File

@ -346,6 +346,18 @@ class EntityCollection extends \ArrayObject implements \JsonSerializable {
return ( new $className() )->fromArray($dataset);
}
public function arrayToEntities(array $list, ? string /*stringable*/ $entityClass = null) : self
{
$collection = new static();
$collection->entityClass = $entityClass ?? $this->entityClass;
foreach($list as $dataset) {
$collection->append($this->arrayToEntity($dataset, $entityClass));
}
return $collection;
}
public function jsonSerialize(): mixed
{
return $this->toArray();

View File

@ -16,7 +16,7 @@ class OrderBy extends Fragment {
return $this;
}
public function add(string $field, ? string $direction = null) : self
public function add(object|string $field, ? string $direction = null) : self
{
$this->validateFieldType($field);

View File

@ -2,6 +2,8 @@
namespace Ulmus\Query;
use Ulmus\Query;
interface QueryBuilderInterface
{
public function push(Fragment $queryFragment) : self;
@ -9,5 +11,5 @@ interface QueryBuilderInterface
public function render(bool $skipToken = false) /* mixed */;
public function reset() : void;
public function getFragment(string $class, int $index = 0) : ? Fragment;
public function removeFragment(Fragment $fragment) : void;
public function removeFragment(Query\Fragment|array|\Stringable|string $fragment) : void;
}

View File

@ -278,7 +278,7 @@ class QueryBuilder implements Query\QueryBuilderInterface
return $this;
}
public function groupBy(string|\Stringable $field, ? string $direction = null) : self
public function groupBy(string|object $field, ? string $direction = null) : self
{
if ( null === $groupBy = $this->getFragment(Query\GroupBy::class) ) {
$groupBy = new Query\GroupBy();

View File

@ -532,7 +532,7 @@ class Repository
return $this;
}
public function orderBy(string|\Stringable $field, ? string $direction = null) : self
public function orderBy(string|object $field, ? string $direction = null) : self
{
$this->queryBuilder->orderBy($field, $direction);
@ -550,8 +550,14 @@ class Repository
public function orders(array $orderList) : self
{
foreach($orderList as $field => $direction) {
if (is_numeric($field)) {
$this->orderBy($direction);
}
else {
# Associative array with direction
$this->orderBy($field, $direction);
}
}
return $this;
}