- Fixed GroupBy

This commit is contained in:
Dave Mc Nicoll 2020-10-06 11:43:31 -04:00
parent 538af38769
commit 5d00a7e394
6 changed files with 25 additions and 22 deletions

View File

@ -4,11 +4,8 @@ namespace Ulmus\Entity\Field;
class Date extends Datetime {
public function __toString()
{
return $this->format("Y-m-d");
}
public string $format = "Y-m-d";
public function formatLocale(string $format) : string
{
return strftime($format, $this->getTimestamp());

View File

@ -4,9 +4,6 @@ namespace Ulmus\Entity\Field;
class Time extends Datetime {
public function __toString()
{
return $this->format("H:i:s");
}
public string $format = "H:i:s";
}

View File

@ -3,22 +3,23 @@
namespace Ulmus\Query;
class GroupBy extends Fragment {
const SQL_TOKEN = "GROUP BY";
public int $order = 70;
public int $order = 75;
public array $groupBy = [];
const SQL_TOKEN = "GROUP BY";
public function set(array $order) : self
{
$this->groupBy = $order;
$this->groupBy = [ $order ];
return $this;
}
public function add(string $field, ? string $direction = null) : self
public function add(string $field) : self
{
$this->groupBy[] = $field;
return $this;
}

View File

@ -4,5 +4,6 @@ namespace Ulmus\Query;
class Having extends Where {
const SQL_TOKEN = "HAVING";
public int $order = 75;
public int $order = 80;
}

View File

@ -3,7 +3,7 @@
namespace Ulmus\Query;
class OrderBy extends Fragment {
public int $order = 80;
public int $order = 85;
public array $orderBy = [];

View File

@ -216,11 +216,6 @@ class QueryBuilder
return $this->where($field, $value, $operator, true);
}
public function groupBy() : self
{
return $this;
}
public function limit(int $value) : self
{
if ( null === $limit = $this->getFragment(Query\Limit::class) ) {
@ -257,6 +252,18 @@ class QueryBuilder
return $this;
}
public function groupBy(string $field, ? string $direction = null) : self
{
if ( null === $groupBy = $this->getFragment(Query\GroupBy::class) ) {
$groupBy = new Query\GroupBy();
$this->push($groupBy);
}
$groupBy->add($field, $direction);
return $this;
}
public function join(string $type, /*string | QueryBuilder*/ $table, $field, $value, bool $outer = false, ? string $alias = null) : self
{
$join = new Query\Join($this);