- 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
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Ulmus\QueryBuilder;
|
||||
|
||||
use Ulmus\Query\QueryFragmentInterface;
|
||||
|
||||
interface QueryBuilderInterface
|
||||
{
|
||||
public function push(QueryFragmentInterface $queryFragment) : self;
|
||||
public function pull(QueryFragmentInterface $queryFragment) : self;
|
||||
public function render(bool $skipToken = false) /* mixed */;
|
||||
public function reset() : void;
|
||||
public function getFragment(string $class, int $index = 0) : ? QueryFragmentInterface;
|
||||
public function removeFragment(QueryFragmentInterface|array|\Stringable|string $fragment) : void;
|
||||
}
|
||||
@@ -3,10 +3,9 @@
|
||||
namespace Ulmus\QueryBuilder\Sql;
|
||||
|
||||
use Ulmus\{ Query };
|
||||
use Ulmus\QueryBuilder\SqlQueryBuilder;
|
||||
|
||||
# Soon to extends SqlQueryBuilder
|
||||
class MssqlQueryBuilder extends MysqlQueryBuilder implements Query\QueryBuilderInterface
|
||||
class MssqlQueryBuilder extends MysqlQueryBuilder
|
||||
{
|
||||
public function limit(int $value) : self
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -3,10 +3,9 @@
|
||||
namespace Ulmus\QueryBuilder\Sql;
|
||||
|
||||
use Ulmus\Query;
|
||||
use Ulmus\QueryBuilder\SqlQueryBuilder;
|
||||
|
||||
# Soon to extends SqlQueryBuilder
|
||||
class SqliteQueryBuilder extends MysqlQueryBuilder implements Query\QueryBuilderInterface
|
||||
class SqliteQueryBuilder extends MysqlQueryBuilder
|
||||
{
|
||||
public function pragma(/*object|Stringable*/ $name, $value = null, bool $callable = false) : self
|
||||
{
|
||||
|
||||
@@ -2,20 +2,18 @@
|
||||
|
||||
namespace Ulmus\QueryBuilder;
|
||||
|
||||
use Ulmus\Query;
|
||||
use Ulmus\Query\Fragment;
|
||||
use Ulmus\Query\QueryBuilderInterface;
|
||||
use Ulmus\Query\QueryFragmentInterface;
|
||||
|
||||
# TODO -> Extract from MysqlQueryBuilder to build an ISO/IEC 9075:2023 compatible layer for a basic SQL QueryBuilder
|
||||
class SqlQueryBuilder implements Query\QueryBuilderInterface
|
||||
class SqlQueryBuilder implements QueryBuilderInterface
|
||||
{
|
||||
|
||||
public function push(Fragment $queryFragment): Query\QueryBuilderInterface
|
||||
public function push(QueryFragmentInterface $queryFragment): QueryBuilderInterface
|
||||
{
|
||||
// TODO: Implement push() method.
|
||||
}
|
||||
|
||||
public function pull(Fragment $queryFragment): Query\QueryBuilderInterface
|
||||
public function pull(QueryFragmentInterface $queryFragment): QueryBuilderInterface
|
||||
{
|
||||
// TODO: Implement pull() method.
|
||||
}
|
||||
@@ -30,12 +28,12 @@ class SqlQueryBuilder implements Query\QueryBuilderInterface
|
||||
// TODO: Implement reset() method.
|
||||
}
|
||||
|
||||
public function getFragment(string $class, int $index = 0): ?Fragment
|
||||
public function getFragment(string $class, int $index = 0): ?QueryFragmentInterface
|
||||
{
|
||||
// TODO: Implement getFragment() method.
|
||||
}
|
||||
|
||||
public function removeFragment(Fragment|\Stringable|array|string $fragment): void
|
||||
public function removeFragment(QueryFragmentInterface|\Stringable|array|string $fragment): void
|
||||
{
|
||||
// TODO: Implement removeFragment() method.
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user