- Added the HAVING and TRUNCATE keyword

- Fixed GroupBy which was not implemented yet
- Added a new SQL raw() function
- From statement now accepts subqueries
This commit is contained in:
Dave Mc Nicoll committed 2020-10-06 11:00:12 -04:00
1 parent 538af38769
commit 139504f8dd
17 files changed
+566 -251

No files matched your search

+50
View File
@@ -6,6 +6,8 @@ use Generator;
class EntityCollection extends \ArrayObject {
public ? string $entityClass = null;
public function filters(Callable $callback) : Generator
{
$idx = 0;
@@ -29,6 +31,17 @@ class EntityCollection extends \ArrayObject {
return $collection;
}
public function iterate(Callable $callback) : array
{
$results = [];
foreach($this as $item) {
$results[] = $callback($item);
}
return $results;
}
public function removeOne($value, string $field, bool $strict = true) : ? object
{
@@ -72,6 +85,17 @@ class EntityCollection extends \ArrayObject {
}
}
public function column($field) : array
{
$list = [];
foreach($this as $item) {
$list[] = $item->$field;
}
return $list;
}
public function buildArray(string $keyColumn, /* string|callable|null */ $value = null) : array
{
$list = [];
@@ -107,4 +131,30 @@ class EntityCollection extends \ArrayObject {
return $list;
}
public function fromArray(array $datasets, ? string $entityClass = null) : self
{
if ( ! ($this->entityClass || $entityClass) ) {
throw new \Exception("An entity class name must be provided to be instanciated and populated before insertion into this collection.");
}
$className = $entityClass ?: $this->entityClass;
foreach($datasets as $dataset) {
$this->append( (new $className() )->fromArray($dataset) );
}
return $this;
}
public function mergeWith( /*array|EntityCollection*/ $datasets ) : self
{
if ( is_object($datasets) ) {
$datasets = $datasets->getArrayCopy();
}
$this->exchangeArray( array_merge( $this->getArrayCopy(), $datasets ) );
return $this;
}
}