Skip to content

Commit

Permalink
Allow type enums in some parameters (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
dlakomski authored Nov 13, 2024
1 parent ed6f847 commit aba25ed
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
14 changes: 7 additions & 7 deletions src/DatabaseSelectBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class DatabaseSelectBuilder
public const DEFAULT_LIMIT = 20;
private QueryBuilder $builder;
private Table $from;
/** @var array<string, string> [class => doctrine type, ...] */
/** @var array<string, string|ParameterType|Type|ArrayParameterType> [class => doctrine type, ...] */
private array $types;
/** @var array<string, string> [model field => query field, ...] */
private array $sortMap = [];
Expand All @@ -31,7 +31,7 @@ final class DatabaseSelectBuilder
/** @var array<string, string> */
private array $fieldSelect = [];

/** @param array<string, string> $types */
/** @param array<string, string|ParameterType|Type|ArrayParameterType> $types */
public function __construct(Connection $connection, array $types = [DateTimeImmutable::class => 'DateTimeImmutable'])
{
$this->builder = $connection->createQueryBuilder();
Expand All @@ -52,7 +52,7 @@ public function resetForConnection(Connection $connection): self
return $copy;
}

/** @param array<string, string> $types */
/** @param array<string, string|ParameterType|Type|ArrayParameterType> $types */
public function withTypes(array $types): self
{
$copy = clone $this;
Expand Down Expand Up @@ -125,7 +125,7 @@ public function rightJoin(Table $join, string $condition): self

/**
* @param array<string, mixed> $params
* @param array<string, string> $types
* @param array<string, string|ParameterType|Type|ArrayParameterType> $types
*/
public function where(string $condition, array $params = [], array $types = []): self
{
Expand All @@ -140,7 +140,7 @@ public function where(string $condition, array $params = [], array $types = []):

/**
* @param array<string, mixed> $params
* @param array<string, string> $types
* @param array<string, string|ParameterType|Type|ArrayParameterType> $types
*/
public function having(string $condition, array $params = [], array $types = []): self
{
Expand Down Expand Up @@ -278,7 +278,7 @@ public function withParameter(string $key, mixed $value, string|ParameterType|Ty

/**
* @param array<string, mixed> $params
* @param array<string|int, string> $types
* @param array<string|int, string|ParameterType|Type|ArrayParameterType> $types
*/
public function withParameters(array $params = [], array $types = []): self
{
Expand Down Expand Up @@ -328,7 +328,7 @@ public function startOffset(): int
return $this->startOffset;
}

private function paramType(mixed $object): string|ParameterType|ArrayParameterType
private function paramType(mixed $object): string|ParameterType|Type|ArrayParameterType
{
if (is_array($object)) {
return ArrayParameterType::STRING;
Expand Down
11 changes: 7 additions & 4 deletions src/Query/AbstractDatabaseQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

namespace GW\DQO\Query;

use Doctrine\DBAL\ArrayParameterType;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Types\Type;
use GW\DQO\DatabaseSelectBuilder;
use GW\DQO\Table;
use function in_array;
Expand Down Expand Up @@ -36,7 +39,7 @@ public function resetForConnection(Connection $connection): self
/**
* @return static
* @param array<string, mixed> $params
* @param array<string, string> $types
* @param array<string, string|ParameterType|Type|ArrayParameterType> $types
*/
public function join(Table $join, string $condition, array $params = [], array $types = []): self
{
Expand All @@ -50,7 +53,7 @@ public function join(Table $join, string $condition, array $params = [], array $
/**
* @return static
* @param array<string, mixed> $params
* @param array<string, string> $types
* @param array<string, string|ParameterType|Type|ArrayParameterType> $types
*/
public function leftJoin(Table $join, string $condition, array $params = [], array $types = []): self
{
Expand All @@ -76,7 +79,7 @@ public function joinOnce(Table $join, string $condition): self
/**
* @return static
* @param array<string, mixed> $params
* @param array<string, string> $types
* @param array<string, string|ParameterType|Type|ArrayParameterType> $types
*/
public function where(string $condition, array $params = [], array $types = []): self
{
Expand All @@ -89,7 +92,7 @@ public function where(string $condition, array $params = [], array $types = []):
/**
* @return static
* @param array<string, mixed> $params
* @param array<string, string> $types
* @param array<string, string|ParameterType|Type|ArrayParameterType> $types
*/
public function having(string $condition, array $params = [], array $types = []): self
{
Expand Down

0 comments on commit aba25ed

Please sign in to comment.