- Started working on decoupling QueryBuilder from SqlQueryBuilder
- WIP on SearchRequest attributes - Began working on removing 'Ulmus' class - WIP on removing SQL query building from Repository (which will become SqlRepository)
This commit is contained in:
1 parent
4571517dc8
commit
9fdebf454d
21 files changed
+114
-127
No files matched your search
@@ -2,8 +2,7 @@
|
||||
|
||||
namespace Ulmus\QueryBuilder\Sql;
|
||||
|
||||
use Ulmus\{Query, Adapter, QueryBuilder\SqlQueryBuilder};
|
||||
use Ulmus\Query\QueryBuilderInterface;
|
||||
use Ulmus\{Query, Adapter, QueryBuilder\SqlQueryBuilder, QueryBuilder\QueryBuilderInterface, Query\QueryFragmentInterface, };
|
||||
|
||||
class MysqlQueryBuilder extends SqlQueryBuilder
|
||||
{
|
||||
@@ -184,7 +183,6 @@ class MysqlQueryBuilder extends SqlQueryBuilder
|
||||
public function close() : self
|
||||
{
|
||||
if ( null !== ($this->where ?? null) && $this->where->parent ) {
|
||||
|
||||
# if an enclosure was opened, and nothing done, we must remove the unused node
|
||||
if ( empty($this->where->conditionList) && (count($this->where->parent->conditionList) === 1) ) {
|
||||
unset($this->where->parent->conditionList);
|
||||
@@ -198,22 +196,14 @@ class MysqlQueryBuilder extends SqlQueryBuilder
|
||||
|
||||
public function where(string|\Stringable $field, mixed $value, string $operator = Query\Where::OPERATOR_EQUAL, string $condition = Query\Where::CONDITION_AND, bool $not = false) : self
|
||||
{
|
||||
# Empty IN case
|
||||
# if ( [] === $value ) {
|
||||
# return $this;
|
||||
# }
|
||||
|
||||
if ( $this->where ?? false ) {
|
||||
$where = $this->where;
|
||||
}
|
||||
elseif ( null === ( $where = $this->getFragment(Query\Where::class) ) ) {
|
||||
$this->where = $where = new Query\Where($this);
|
||||
$this->push($where);
|
||||
if ( empty($this->where) && ! $this->getFragment(Query\Where::class) ) {
|
||||
$this->where = new Query\Where($this);
|
||||
$this->push($this->where);
|
||||
}
|
||||
|
||||
$this->whereConditionOperator = $operator;
|
||||
|
||||
$where->add($field, $value, $operator, $condition, $not);
|
||||
$this->where->add($field, $value, $operator, $condition, $not);
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -225,16 +215,13 @@ class MysqlQueryBuilder extends SqlQueryBuilder
|
||||
|
||||
public function having(string|\Stringable $field, mixed $value, string $operator = Query\Where::OPERATOR_EQUAL, string $condition = Query\Where::CONDITION_AND, bool $not = false) : self
|
||||
{
|
||||
if ( $this->having ?? false ) {
|
||||
$having = $this->having;
|
||||
}
|
||||
elseif ( null === ( $having = $this->getFragment(Query\Having::class) ) ) {
|
||||
$this->having = $having = new Query\Having($this);
|
||||
$this->push($having);
|
||||
if ( empty($this->having) && ! $this->getFragment(Query\Having::class) ) {
|
||||
$this->having = new Query\Having($this);
|
||||
$this->push($this->having);
|
||||
}
|
||||
|
||||
$this->havingConditionOperator = $operator;
|
||||
$having->add($field, $value, $operator, $condition, $not);
|
||||
$this->having->add($field, $value, $operator, $condition, $not);
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -262,7 +249,7 @@ class MysqlQueryBuilder extends SqlQueryBuilder
|
||||
$this->push($offset);
|
||||
|
||||
# A limit is required to match an offset
|
||||
if ( null === $limit = $this->getFragment(Query\Limit::class) ) {
|
||||
if ( null === $this->getFragment(Query\Limit::class) ) {
|
||||
$this->limit(\PHP_INT_MAX);
|
||||
}
|
||||
}
|
||||
@@ -284,14 +271,14 @@ class MysqlQueryBuilder extends SqlQueryBuilder
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function groupBy(string|object $field, ? string $direction = null) : self
|
||||
public function groupBy(string|object $field) : self
|
||||
{
|
||||
if ( null === $groupBy = $this->getFragment(Query\GroupBy::class) ) {
|
||||
$groupBy = new Query\GroupBy();
|
||||
$this->push($groupBy);
|
||||
}
|
||||
|
||||
$groupBy->add($field, $direction);
|
||||
$groupBy->add($field);
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -432,14 +419,14 @@ class MysqlQueryBuilder extends SqlQueryBuilder
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function push(Query\Fragment $queryFragment) : self
|
||||
public function push(QueryFragmentInterface $queryFragment) : self
|
||||
{
|
||||
$this->queryStack[] = $queryFragment;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function pull(Query\Fragment $queryFragment) : self
|
||||
public function pull(QueryFragmentInterface $queryFragment) : self
|
||||
{
|
||||
return array_shift($this->queryStack);
|
||||
}
|
||||
@@ -469,7 +456,7 @@ class MysqlQueryBuilder extends SqlQueryBuilder
|
||||
unset($this->where, $this->having);
|
||||
}
|
||||
|
||||
public function getFragment(string $class, int $index = 0) : ? Query\Fragment
|
||||
public function getFragment(string $class, int $index = 0) : ? QueryFragmentInterface
|
||||
{
|
||||
foreach($this->queryStack as $item) {
|
||||
if ( is_a($item, $class, true) ) {
|
||||
@@ -482,7 +469,7 @@ class MysqlQueryBuilder extends SqlQueryBuilder
|
||||
return null;
|
||||
}
|
||||
|
||||
public function removeFragment(Query\Fragment|array|\Stringable|string $fragment) : void
|
||||
public function removeFragment(QueryFragmentInterface|array|\Stringable|string $fragment) : void
|
||||
{
|
||||
is_object($fragment) && $fragment = get_class($fragment);
|
||||
|
||||
@@ -500,7 +487,7 @@ class MysqlQueryBuilder extends SqlQueryBuilder
|
||||
}
|
||||
}
|
||||
|
||||
public function getFragments(Query\Fragment|array|\Stringable|string $fragment = null) : array
|
||||
public function getFragments(QueryFragmentInterface|array|\Stringable|string $fragment = null) : array
|
||||
{
|
||||
return $fragment !== null ? array_filter($this->queryStack, fn($e) => is_a($e, $fragment, true) ) : $this->queryStack;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user