greatest/least expression

This commit is contained in:
Yuri Kuznetsov
2023-02-22 11:51:10 +02:00
parent a06bfde766
commit 7d4ab54505
+17 -1
View File
@@ -48,7 +48,7 @@ class Expression implements WhereItem
throw new RuntimeException("Expression can't be empty.");
}
if (substr($expression, -1) === ':') {
if (str_ends_with($expression, ':')) {
throw new RuntimeException("Expression should not end with `:`.");
}
@@ -653,6 +653,22 @@ class Expression implements WhereItem
return self::composeFunction('ROUND', $number, $precision);
}
/**
* 'GREATEST' function. A max value from a list of expressions.
*/
public static function greatest(Expression ...$expressionList): self
{
return self::composeFunction('GREATEST', ...$expressionList);
}
/**
* 'LEAST' function. A min value from a list of expressions.
*/
public static function least(Expression ...$expressionList): self
{
return self::composeFunction('LEAST', ...$expressionList);
}
/**
* 'AND' operator. Returns TRUE if all arguments are TRUE.
*/