add count() as shortcut for count('*') in FunctionBuilder

Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
Robin Appelman 2019-10-25 16:55:08 +02:00
parent 0e9feeb090
commit ac209cea52
No known key found for this signature in database
GPG Key ID: 42B69D8A64526EFB
2 changed files with 4 additions and 3 deletions

View File

@ -72,9 +72,10 @@ class FunctionBuilder implements IFunctionBuilder {
return new QueryFunction($this->helper->quoteColumnName($x) . ' - ' . $this->helper->quoteColumnName($y));
}
public function count($count, $alias = '') {
public function count($count = '', $alias = '') {
$alias = $alias ? (' AS ' . $this->helper->quoteColumnName($alias)) : '';
return new QueryFunction('COUNT(' . $this->helper->quoteColumnName($count) . ')' . $alias);
$quotedName = $count === '' ? '*' : $this->helper->quoteColumnName($count);
return new QueryFunction('COUNT(' . $quotedName . ')' . $alias);
}
public function max($field) {

View File

@ -104,7 +104,7 @@ interface IFunctionBuilder {
* @return IQueryFunction
* @since 14.0.0
*/
public function count($count, $alias = '');
public function count($count = '', $alias = '');
/**
* Takes the maximum of all rows in a column