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

Restore Query::one interface #798

Merged
merged 13 commits into from
Aug 22, 2024
2 changes: 1 addition & 1 deletion src/Command/AbstractCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ public function queryColumn(): array
return is_array($results) ? $results : [];
}

public function queryOne(): array|null
public function queryOne(): array|object|null
{
/** @psalm-var mixed $results */
$results = $this->queryInternal(self::QUERY_MODE_ROW);
Expand Down
4 changes: 2 additions & 2 deletions src/Command/CommandInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -631,10 +631,10 @@ public function queryColumn(): array;
* @throws Exception
* @throws Throwable If execution failed.
*
* @return array|null The first row (in terms of an array) of the query result. Null if the query
* @return array|object|null The first row (in terms of an array) of the query result. Null if the query
Tigrov marked this conversation as resolved.
Show resolved Hide resolved
* results in nothing.
*/
public function queryOne(): array|null;
public function queryOne(): array|object|null;

/**
* Execute the SQL statement and returns the value of the first column in the first row of data.
Expand Down
2 changes: 1 addition & 1 deletion src/Debug/CommandInterfaceProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ public function queryColumn(): array
/**
* @psalm-suppress PossiblyUndefinedArrayOffset
*/
public function queryOne(): array|null
public function queryOne(): array|object|null
{
[$callStack] = debug_backtrace();

Expand Down
4 changes: 1 addition & 3 deletions src/Query/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ public function offset(ExpressionInterface|int|null $offset): static
return $this;
}

public function one(): array|null
public function one(): array|object|null
{
return match ($this->emulateExecution) {
true => null,
Expand Down Expand Up @@ -680,8 +680,6 @@ public function withQueries(array $withQueries): static
*
* Restores the value of select to make this query reusable.
*
* @param ExpressionInterface|string $selectExpression
*
* @throws Exception
* @throws InvalidArgumentException
* @throws InvalidConfigException
Expand Down
9 changes: 5 additions & 4 deletions src/Query/QueryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public function addParams(array $params): static;
* @throws InvalidConfigException
* @throws Throwable
*
* @return array[] The query results. If the query results in nothing, it returns an empty array.
* @return array The query results. If the query results in nothing, it returns an empty array.
* @psalm-return array[]|object[]
Tigrov marked this conversation as resolved.
Show resolved Hide resolved
*/
public function all(): array;

Expand Down Expand Up @@ -254,10 +255,10 @@ public function getWithQueries(): array;
* @throws InvalidConfigException
* @throws Throwable
*
* @return array|null The first row (in terms of an array) of the query result. It returns `null` if the query
* results in nothing.
* @return array|object|null The first row (as array or object) of the query result.
* It returns `null` if the query results in nothing.
*/
public function one(): array|null;
public function one(): array|object|null;
vjik marked this conversation as resolved.
Show resolved Hide resolved

/**
* Sets the parameters to bind to the query.
Expand Down
Loading