-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
44 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of PHP CS Fixer. | ||
* (c) Fabien Potencier <[email protected]> | ||
* Dariusz Rumiński <[email protected]> | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace GemLibrary\Database; | ||
|
||
use GemLibrary\Database\PdoQuery; | ||
use GemLibrary\Database\Query\Delete; | ||
use GemLibrary\Database\Query\Insert; | ||
use GemLibrary\Database\Query\Select; | ||
use GemLibrary\Database\Query\Update; | ||
|
||
class QueryBuilder | ||
class QueryBuilder extends PdoQuery | ||
{ | ||
public static function select(string ...$select): Select | ||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
public function select(string ...$select): Select | ||
{ | ||
return new Select($select); | ||
} | ||
|
||
/** | ||
* @param string $intoTable | ||
*/ | ||
public static function insert(string $intoTable): Insert | ||
public function insert(string $intoTable): Insert | ||
{ | ||
return new Insert($intoTable); | ||
} | ||
|
||
/** | ||
* @param string $table | ||
*/ | ||
public static function update(string $table): Update | ||
public function update(string $table): Update | ||
{ | ||
return new Update($table); | ||
} | ||
|
@@ -44,7 +40,7 @@ public static function update(string $table): Update | |
* @param string $table | ||
* Delete from table | ||
*/ | ||
public static function delete(string $table): Delete | ||
public function delete(string $table): Delete | ||
{ | ||
return new Delete($table); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of PHP CS Fixer. | ||
* (c) Fabien Potencier <[email protected]> | ||
* Dariusz Rumiński <[email protected]> | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace GemLibrary\Database\Query; | ||
|
||
use GemLibrary\Database\PdoQuery; | ||
use GemLibrary\Database\QueryBuilder; | ||
use GemLibrary\Database\QueryBuilderInterface; | ||
use GemLibrary\Database\QueryProvider; | ||
|
||
class Select implements QueryBuilderInterface | ||
class Select extends QueryBuilder implements QueryBuilderInterface | ||
{ | ||
use LimitTrait; | ||
use WhereTrait; | ||
|
@@ -71,6 +59,8 @@ class Select implements QueryBuilderInterface | |
|
||
private ?int $offset = null; | ||
|
||
//private QueryBuilder $queryBuilder; | ||
|
||
/** | ||
* @param array<mixed> $select | ||
*/ | ||
|
@@ -79,6 +69,13 @@ public function __construct(array $select) | |
$this->fields = $select; | ||
} | ||
|
||
// public function setQueryBuilder(QueryBuilder $queryBuilder): self | ||
// { | ||
// $this->queryBuilder = $queryBuilder; | ||
|
||
// return $this; | ||
// } | ||
|
||
public function __toString(): string | ||
{ | ||
$this->query = $this->selectMaker() . implode(', ', $this->from) | ||
|
@@ -141,24 +138,24 @@ public function leftJoin(string ...$join): self | |
/** | ||
* @param QueryProvider $queryProvider | ||
*/ | ||
public function run(PdoQuery $queryProvider): self | ||
public function run(): self | ||
{ | ||
$this->result = $queryProvider->selectQuery($this->query, $this->arrayBindValues); | ||
$this->result = $this->selectQuery($this->query, $this->arrayBindValues); | ||
|
||
return $this; | ||
} | ||
|
||
public function count(PdoQuery $queryProvider): self | ||
public function count(): self | ||
{ | ||
$this->result = $queryProvider->countQuery($this->query, $this->arrayBindValues); | ||
$this->result = $this->countQuery($this->query, $this->arrayBindValues); | ||
|
||
return $this; | ||
} | ||
|
||
public function json(PdoQuery $queryProvider): self | ||
public function json(): self | ||
{ | ||
$array = []; | ||
$result = $queryProvider->selectQuery($this->query, $this->arrayBindValues); | ||
$result = $this->selectQuery($this->query, $this->arrayBindValues); | ||
if (\is_array($result)) { | ||
foreach ($result as $item) { | ||
$encoded = json_encode($item, JSON_PRETTY_PRINT); | ||
|
@@ -179,10 +176,10 @@ public function json(PdoQuery $queryProvider): self | |
* @param object $object | ||
* retrun array of Objects | ||
*/ | ||
public function object(PdoQuery $queryProvider, object $object): self | ||
public function object(object $object): self | ||
{ | ||
$class = $object::class; | ||
$result = $queryProvider->selectQuery($this->query, $this->arrayBindValues); | ||
$result = $this->selectQuery($this->query, $this->arrayBindValues); | ||
if (\is_array($result)) { | ||
foreach ($result as $item) { | ||
if (\is_array($item)) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters