Class FunctionsBuilder
Contains methods related to generating FunctionExpression objects with most commonly used SQL functions. This acts as a factory for FunctionExpression objects.
Method Summary
- 
          __call() publicMagic method dispatcher to create custom SQL function calls 
- 
          aggregate() publicHelper method to create arbitrary SQL aggregate function calls. 
- 
          avg() publicReturns a AggregateExpression representing a call to SQL AVG function. 
- 
          cast() publicReturns a FunctionExpression representing a SQL CAST. 
- 
          coalesce() publicReturns a FunctionExpression representing a call to SQL COALESCE function. 
- 
          concat() publicReturns a FunctionExpression representing a string concatenation 
- 
          count() publicReturns a AggregateExpression representing a call to SQL COUNT function. 
- 
          dateAdd() publicAdd the time unit to the date expression 
- 
          dateDiff() publicReturns a FunctionExpression representing the difference in days between two dates. 
- 
          datePart() publicReturns the specified date part from the SQL expression. 
- 
          dayOfWeek() publicReturns a FunctionExpression representing a call to SQL WEEKDAY function. 1 - Sunday, 2 - Monday, 3 - Tuesday... 
- 
          extract() publicReturns the specified date part from the SQL expression. 
- 
          jsonValue() publicReturns a FunctionExpression representing the Json Value 
- 
          lag() publicReturns an AggregateExpression representing call to SQL LAG(). 
- 
          lead() publicReturns an AggregateExpression representing call to SQL LEAD(). 
- 
          max() publicReturns a AggregateExpression representing a call to SQL MAX function. 
- 
          min() publicReturns a AggregateExpression representing a call to SQL MIN function. 
- 
          now() publicReturns a FunctionExpression representing a call that will return the current date and time. By default it returns both date and time, but you can also make it generate only the date or only the time. 
- 
          rand() publicReturns a FunctionExpression representing a call to SQL RAND function. 
- 
          rowNumber() publicReturns an AggregateExpression representing call to SQL ROW_NUMBER(). 
- 
          sum() publicReturns a AggregateExpression representing a call to SQL SUM function. 
- 
          toLiteralParam() protectedCreates function parameter array from expression or string literal. 
- 
          weekday() publicReturns a FunctionExpression representing a call to SQL WEEKDAY function. 1 - Sunday, 2 - Monday, 3 - Tuesday... 
Method Detail
__call() ¶ public
__call(string $name, array $args): Cake\Database\Expression\FunctionExpressionMagic method dispatcher to create custom SQL function calls
Parameters
- 
                string$name
- the SQL function name to construct 
- 
                array$args
- list with up to 3 arguments, first one being an array with parameters for the SQL function, the second one a list of types to bind to those params, and the third one the return type of the function 
Returns
Cake\Database\Expression\FunctionExpressionaggregate() ¶ public
aggregate(string $name, array $params = [], array $types = [], string $return = 'float'): Cake\Database\Expression\AggregateExpressionHelper method to create arbitrary SQL aggregate function calls.
Parameters
- 
                string$name
- The SQL aggregate function name 
- 
                array$params optional
- Array of arguments to be passed to the function. Can be an associative array with the literal value or identifier: - ['value' => 'literal']or `['value' => 'identifier']
- 
                array$types optional
- Array of types that match the names used in - $params:- ['name' => 'type']
- 
                string$return optional
- Return type of the entire expression. Defaults to float. 
Returns
Cake\Database\Expression\AggregateExpressionavg() ¶ public
avg(Cake\Database\ExpressionInterface|string $expression, array $types = []): Cake\Database\Expression\AggregateExpressionReturns a AggregateExpression representing a call to SQL AVG function.
Parameters
- 
                Cake\Database\ExpressionInterface|string$expression
- the function argument 
- 
                array$types optional
- list of types to bind to the arguments 
Returns
Cake\Database\Expression\AggregateExpressioncast() ¶ public
cast(Cake\Database\ExpressionInterface|string $field, string $dataType): Cake\Database\Expression\FunctionExpressionReturns a FunctionExpression representing a SQL CAST.
The $type parameter is a SQL type. The return type for the returned expression
is the default type name. Use setReturnType() to update it.
Parameters
- 
                Cake\Database\ExpressionInterface|string$field
- Field or expression to cast. 
- 
                string$dataType
- The SQL data type 
Returns
Cake\Database\Expression\FunctionExpressioncoalesce() ¶ public
coalesce(array $args, array $types = []): Cake\Database\Expression\FunctionExpressionReturns a FunctionExpression representing a call to SQL COALESCE function.
Parameters
- 
                array$args
- List of expressions to evaluate as function parameters 
- 
                array$types optional
- list of types to bind to the arguments 
Returns
Cake\Database\Expression\FunctionExpressionconcat() ¶ public
concat(array $args, array $types = []): Cake\Database\Expression\FunctionExpressionReturns a FunctionExpression representing a string concatenation
Parameters
- 
                array$args
- List of strings or expressions to concatenate 
- 
                array$types optional
- list of types to bind to the arguments 
Returns
Cake\Database\Expression\FunctionExpressioncount() ¶ public
count(Cake\Database\ExpressionInterface|string $expression, array $types = []): Cake\Database\Expression\AggregateExpressionReturns a AggregateExpression representing a call to SQL COUNT function.
Parameters
- 
                Cake\Database\ExpressionInterface|string$expression
- the function argument 
- 
                array$types optional
- list of types to bind to the arguments 
Returns
Cake\Database\Expression\AggregateExpressiondateAdd() ¶ public
dateAdd(Cake\Database\ExpressionInterface|string $expression, string|int $value, string $unit, array $types = []): Cake\Database\Expression\FunctionExpressionAdd the time unit to the date expression
Parameters
- 
                Cake\Database\ExpressionInterface|string$expression
- Expression to obtain the date part from. 
- 
                string|int$value
- Value to be added. Use negative to subtract. 
- 
                string$unit
- Unit of the value e.g. hour or day. 
- 
                array$types optional
- list of types to bind to the arguments 
Returns
Cake\Database\Expression\FunctionExpressiondateDiff() ¶ public
dateDiff(array $args, array $types = []): Cake\Database\Expression\FunctionExpressionReturns a FunctionExpression representing the difference in days between two dates.
Parameters
- 
                array$args
- List of expressions to obtain the difference in days. 
- 
                array$types optional
- list of types to bind to the arguments 
Returns
Cake\Database\Expression\FunctionExpressiondatePart() ¶ public
datePart(string $part, Cake\Database\ExpressionInterface|string $expression, array $types = []): Cake\Database\Expression\FunctionExpressionReturns the specified date part from the SQL expression.
Parameters
- 
                string$part
- Part of the date to return. 
- 
                Cake\Database\ExpressionInterface|string$expression
- Expression to obtain the date part from. 
- 
                array$types optional
- list of types to bind to the arguments 
Returns
Cake\Database\Expression\FunctionExpressiondayOfWeek() ¶ public
dayOfWeek(Cake\Database\ExpressionInterface|string $expression, array $types = []): Cake\Database\Expression\FunctionExpressionReturns a FunctionExpression representing a call to SQL WEEKDAY function. 1 - Sunday, 2 - Monday, 3 - Tuesday...
Parameters
- 
                Cake\Database\ExpressionInterface|string$expression
- the function argument 
- 
                array$types optional
- list of types to bind to the arguments 
Returns
Cake\Database\Expression\FunctionExpressionextract() ¶ public
extract(string $part, Cake\Database\ExpressionInterface|string $expression, array $types = []): Cake\Database\Expression\FunctionExpressionReturns the specified date part from the SQL expression.
Parameters
- 
                string$part
- Part of the date to return. 
- 
                Cake\Database\ExpressionInterface|string$expression
- Expression to obtain the date part from. 
- 
                array$types optional
- list of types to bind to the arguments 
Returns
Cake\Database\Expression\FunctionExpressionjsonValue() ¶ public
jsonValue(Cake\Database\ExpressionInterface|string $expression, string $jsonPath, array $types = []): Cake\Database\Expression\FunctionExpressionReturns a FunctionExpression representing the Json Value
Parameters
- 
                Cake\Database\ExpressionInterface|string$expression
- The Json value or json field 
- 
                string$jsonPath
- A valid JSON PATH Query 
- 
                array$types optional
- list of types to bind to the arguments 
Returns
Cake\Database\Expression\FunctionExpressionlag() ¶ public
lag(Cake\Database\ExpressionInterface|string $expression, int $offset, mixed $default = null, string|null $type = null): Cake\Database\Expression\AggregateExpressionReturns an AggregateExpression representing call to SQL LAG().
Parameters
- 
                Cake\Database\ExpressionInterface|string$expression
- The value evaluated at offset 
- 
                int$offset
- The row offset 
- 
                mixed$default optional
- The default value if offset doesn't exist 
- 
                string|null$type optional
- The output type of the lag expression. Defaults to float. 
Returns
Cake\Database\Expression\AggregateExpressionlead() ¶ public
lead(Cake\Database\ExpressionInterface|string $expression, int $offset, mixed $default = null, string|null $type = null): Cake\Database\Expression\AggregateExpressionReturns an AggregateExpression representing call to SQL LEAD().
Parameters
- 
                Cake\Database\ExpressionInterface|string$expression
- The value evaluated at offset 
- 
                int$offset
- The row offset 
- 
                mixed$default optional
- The default value if offset doesn't exist 
- 
                string|null$type optional
- The output type of the lead expression. Defaults to float. 
Returns
Cake\Database\Expression\AggregateExpressionmax() ¶ public
max(Cake\Database\ExpressionInterface|string $expression, array $types = []): Cake\Database\Expression\AggregateExpressionReturns a AggregateExpression representing a call to SQL MAX function.
Parameters
- 
                Cake\Database\ExpressionInterface|string$expression
- the function argument 
- 
                array$types optional
- list of types to bind to the arguments 
Returns
Cake\Database\Expression\AggregateExpressionmin() ¶ public
min(Cake\Database\ExpressionInterface|string $expression, array $types = []): Cake\Database\Expression\AggregateExpressionReturns a AggregateExpression representing a call to SQL MIN function.
Parameters
- 
                Cake\Database\ExpressionInterface|string$expression
- the function argument 
- 
                array$types optional
- list of types to bind to the arguments 
Returns
Cake\Database\Expression\AggregateExpressionnow() ¶ public
now(string $type = 'datetime'): Cake\Database\Expression\FunctionExpressionReturns a FunctionExpression representing a call that will return the current date and time. By default it returns both date and time, but you can also make it generate only the date or only the time.
Parameters
- 
                string$type optional
- (datetime|date|time) 
Returns
Cake\Database\Expression\FunctionExpressionrand() ¶ public
rand(): Cake\Database\Expression\FunctionExpressionReturns a FunctionExpression representing a call to SQL RAND function.
Returns
Cake\Database\Expression\FunctionExpressionrowNumber() ¶ public
rowNumber(): Cake\Database\Expression\AggregateExpressionReturns an AggregateExpression representing call to SQL ROW_NUMBER().
Returns
Cake\Database\Expression\AggregateExpressionsum() ¶ public
sum(Cake\Database\ExpressionInterface|string $expression, array $types = []): Cake\Database\Expression\AggregateExpressionReturns a AggregateExpression representing a call to SQL SUM function.
Parameters
- 
                Cake\Database\ExpressionInterface|string$expression
- the function argument 
- 
                array$types optional
- list of types to bind to the arguments 
Returns
Cake\Database\Expression\AggregateExpressiontoLiteralParam() ¶ protected
toLiteralParam(Cake\Database\ExpressionInterface|string $expression): array<Cake\Database\ExpressionInterface|string>Creates function parameter array from expression or string literal.
Parameters
- 
                Cake\Database\ExpressionInterface|string$expression
- function argument 
Returns
array<Cake\Database\ExpressionInterface|string>weekday() ¶ public
weekday(Cake\Database\ExpressionInterface|string $expression, array $types = []): Cake\Database\Expression\FunctionExpressionReturns a FunctionExpression representing a call to SQL WEEKDAY function. 1 - Sunday, 2 - Monday, 3 - Tuesday...
Parameters
- 
                Cake\Database\ExpressionInterface|string$expression
- the function argument 
- 
                array$types optional
- list of types to bind to the arguments 
Returns
Cake\Database\Expression\FunctionExpression