Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow type enums in some parameters #36

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading