Skip to content
Open
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
6 changes: 4 additions & 2 deletions src/Query/SelectQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,12 +326,14 @@ public function runChunks(int $limit, callable $callback): void
*
* @psalm-param non-empty-string $column Column to count by (every column by default).
*/
public function count(string $column = '*'): int
public function count(string $column = '*', bool $distinct = false): int
{
$select = clone $this;

//To be escaped in compiler
$select->columns = ["COUNT({$column})"];
$select->columns = [
$distinct === true ? "COUNT(DISTINCT({$column}))" : "COUNT({$column})",
];
$select->orderBy = [];
$select->groupBy = [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ public function testCountDistinct(): void
],
);

$this->assertSame(4, $table->select()->count('id', true));
Copy link
Member

@roxblnfk roxblnfk Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please test it in a new function. The both cases should be covered

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ready

$this->assertSame(4, $table->select()->count('DISTINCT(id)'));
}

Expand Down
Loading