FunctionsBuilder
in package
Contains methods related to generating FunctionExpression objects with most commonly used SQL functions.
This acts as a factory for FunctionExpression objects.
Table of Contents
Methods
- __call() : FunctionExpression
- Magic method dispatcher to create custom SQL function calls
- aggregate() : AggregateExpression
- Helper method to create arbitrary SQL aggregate function calls.
- avg() : AggregateExpression
- Returns a AggregateExpression representing a call to SQL AVG function.
- cast() : FunctionExpression
- Returns a FunctionExpression representing a SQL CAST.
- coalesce() : FunctionExpression
- Returns a FunctionExpression representing a call to SQL COALESCE function.
- concat() : FunctionExpression
- Returns a FunctionExpression representing a string concatenation
- count() : AggregateExpression
- Returns a AggregateExpression representing a call to SQL COUNT function.
- dateAdd() : FunctionExpression
- Add the time unit to the date expression
- dateDiff() : FunctionExpression
- Returns a FunctionExpression representing the difference in days between two dates.
- datePart() : FunctionExpression
- Returns the specified date part from the SQL expression.
- dayOfWeek() : FunctionExpression
- Returns a FunctionExpression representing a call to SQL WEEKDAY function.
- extract() : FunctionExpression
- Returns the specified date part from the SQL expression.
- lag() : AggregateExpression
- Returns an AggregateExpression representing call to SQL LAG().
- lead() : AggregateExpression
- Returns an AggregateExpression representing call to SQL LEAD().
- max() : AggregateExpression
- Returns a AggregateExpression representing a call to SQL MAX function.
- min() : AggregateExpression
- Returns a AggregateExpression representing a call to SQL MIN function.
- now() : FunctionExpression
- Returns 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() : FunctionExpression
- Returns a FunctionExpression representing a call to SQL RAND function.
- rowNumber() : AggregateExpression
- Returns an AggregateExpression representing call to SQL ROW_NUMBER().
- sum() : AggregateExpression
- Returns a AggregateExpression representing a call to SQL SUM function.
- weekday() : FunctionExpression
- Returns a FunctionExpression representing a call to SQL WEEKDAY function.
- toLiteralParam() : array<string|int, ExpressionInterface|string>
- Creates function parameter array from expression or string literal.
Methods
__call()
Magic method dispatcher to create custom SQL function calls
public
__call(string $name, array<string|int, mixed> $args) : FunctionExpression
Parameters
- $name : string
-
the SQL function name to construct
- $args : array<string|int, mixed>
-
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
Return values
FunctionExpressionaggregate()
Helper method to create arbitrary SQL aggregate function calls.
public
aggregate(string $name[, array<string|int, mixed> $params = [] ][, array<string|int, mixed> $types = [] ][, string $return = 'float' ]) : AggregateExpression
Parameters
- $name : string
-
The SQL aggregate function name
- $params : array<string|int, mixed> = []
-
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'] - $types : array<string|int, mixed> = []
-
Array of types that match the names used in
$params
:['name' => 'type']
- $return : string = 'float'
-
Return type of the entire expression. Defaults to float.
Return values
AggregateExpressionavg()
Returns a AggregateExpression representing a call to SQL AVG function.
public
avg(ExpressionInterface|string $expression[, array<string|int, mixed> $types = [] ]) : AggregateExpression
Parameters
- $expression : ExpressionInterface|string
-
the function argument
- $types : array<string|int, mixed> = []
-
list of types to bind to the arguments
Return values
AggregateExpressioncast()
Returns a FunctionExpression representing a SQL CAST.
public
cast(ExpressionInterface|string $field[, string $type = '' ]) : FunctionExpression
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
- $field : ExpressionInterface|string
-
Field or expression to cast.
- $type : string = ''
-
The SQL data type
Return values
FunctionExpressioncoalesce()
Returns a FunctionExpression representing a call to SQL COALESCE function.
public
coalesce(array<string|int, mixed> $args[, array<string|int, mixed> $types = [] ]) : FunctionExpression
Parameters
- $args : array<string|int, mixed>
-
List of expressions to evaluate as function parameters
- $types : array<string|int, mixed> = []
-
list of types to bind to the arguments
Return values
FunctionExpressionconcat()
Returns a FunctionExpression representing a string concatenation
public
concat(array<string|int, mixed> $args[, array<string|int, mixed> $types = [] ]) : FunctionExpression
Parameters
- $args : array<string|int, mixed>
-
List of strings or expressions to concatenate
- $types : array<string|int, mixed> = []
-
list of types to bind to the arguments
Return values
FunctionExpressioncount()
Returns a AggregateExpression representing a call to SQL COUNT function.
public
count(ExpressionInterface|string $expression[, array<string|int, mixed> $types = [] ]) : AggregateExpression
Parameters
- $expression : ExpressionInterface|string
-
the function argument
- $types : array<string|int, mixed> = []
-
list of types to bind to the arguments
Return values
AggregateExpressiondateAdd()
Add the time unit to the date expression
public
dateAdd(ExpressionInterface|string $expression, string|int $value, string $unit[, array<string|int, mixed> $types = [] ]) : FunctionExpression
Parameters
- $expression : ExpressionInterface|string
-
Expression to obtain the date part from.
- $value : string|int
-
Value to be added. Use negative to subtract.
- $unit : string
-
Unit of the value e.g. hour or day.
- $types : array<string|int, mixed> = []
-
list of types to bind to the arguments
Return values
FunctionExpressiondateDiff()
Returns a FunctionExpression representing the difference in days between two dates.
public
dateDiff(array<string|int, mixed> $args[, array<string|int, mixed> $types = [] ]) : FunctionExpression
Parameters
- $args : array<string|int, mixed>
-
List of expressions to obtain the difference in days.
- $types : array<string|int, mixed> = []
-
list of types to bind to the arguments
Return values
FunctionExpressiondatePart()
Returns the specified date part from the SQL expression.
public
datePart(string $part, ExpressionInterface|string $expression[, array<string|int, mixed> $types = [] ]) : FunctionExpression
Parameters
- $part : string
-
Part of the date to return.
- $expression : ExpressionInterface|string
-
Expression to obtain the date part from.
- $types : array<string|int, mixed> = []
-
list of types to bind to the arguments
Return values
FunctionExpressiondayOfWeek()
Returns a FunctionExpression representing a call to SQL WEEKDAY function.
public
dayOfWeek(ExpressionInterface|string $expression[, array<string|int, mixed> $types = [] ]) : FunctionExpression
1 - Sunday, 2 - Monday, 3 - Tuesday...
Parameters
- $expression : ExpressionInterface|string
-
the function argument
- $types : array<string|int, mixed> = []
-
list of types to bind to the arguments
Return values
FunctionExpressionextract()
Returns the specified date part from the SQL expression.
public
extract(string $part, ExpressionInterface|string $expression[, array<string|int, mixed> $types = [] ]) : FunctionExpression
Parameters
- $part : string
-
Part of the date to return.
- $expression : ExpressionInterface|string
-
Expression to obtain the date part from.
- $types : array<string|int, mixed> = []
-
list of types to bind to the arguments
Return values
FunctionExpressionlag()
Returns an AggregateExpression representing call to SQL LAG().
public
lag(ExpressionInterface|string $expression, int $offset[, mixed $default = null ][, string $type = null ]) : AggregateExpression
Parameters
- $expression : ExpressionInterface|string
-
The value evaluated at offset
- $offset : int
-
The row offset
- $default : mixed = null
-
The default value if offset doesn't exist
- $type : string = null
-
The output type of the lag expression. Defaults to float.
Return values
AggregateExpressionlead()
Returns an AggregateExpression representing call to SQL LEAD().
public
lead(ExpressionInterface|string $expression, int $offset[, mixed $default = null ][, string $type = null ]) : AggregateExpression
Parameters
- $expression : ExpressionInterface|string
-
The value evaluated at offset
- $offset : int
-
The row offset
- $default : mixed = null
-
The default value if offset doesn't exist
- $type : string = null
-
The output type of the lead expression. Defaults to float.
Return values
AggregateExpressionmax()
Returns a AggregateExpression representing a call to SQL MAX function.
public
max(ExpressionInterface|string $expression[, array<string|int, mixed> $types = [] ]) : AggregateExpression
Parameters
- $expression : ExpressionInterface|string
-
the function argument
- $types : array<string|int, mixed> = []
-
list of types to bind to the arguments
Return values
AggregateExpressionmin()
Returns a AggregateExpression representing a call to SQL MIN function.
public
min(ExpressionInterface|string $expression[, array<string|int, mixed> $types = [] ]) : AggregateExpression
Parameters
- $expression : ExpressionInterface|string
-
the function argument
- $types : array<string|int, mixed> = []
-
list of types to bind to the arguments
Return values
AggregateExpressionnow()
Returns 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.
public
now([string $type = 'datetime' ]) : FunctionExpression
Parameters
- $type : string = 'datetime'
-
(datetime|date|time)
Return values
FunctionExpressionrand()
Returns a FunctionExpression representing a call to SQL RAND function.
public
rand() : FunctionExpression
Return values
FunctionExpressionrowNumber()
Returns an AggregateExpression representing call to SQL ROW_NUMBER().
public
rowNumber() : AggregateExpression
Return values
AggregateExpressionsum()
Returns a AggregateExpression representing a call to SQL SUM function.
public
sum(ExpressionInterface|string $expression[, array<string|int, mixed> $types = [] ]) : AggregateExpression
Parameters
- $expression : ExpressionInterface|string
-
the function argument
- $types : array<string|int, mixed> = []
-
list of types to bind to the arguments
Return values
AggregateExpressionweekday()
Returns a FunctionExpression representing a call to SQL WEEKDAY function.
public
weekday(ExpressionInterface|string $expression[, array<string|int, mixed> $types = [] ]) : FunctionExpression
1 - Sunday, 2 - Monday, 3 - Tuesday...
Parameters
- $expression : ExpressionInterface|string
-
the function argument
- $types : array<string|int, mixed> = []
-
list of types to bind to the arguments
Return values
FunctionExpressiontoLiteralParam()
Creates function parameter array from expression or string literal.
protected
toLiteralParam(ExpressionInterface|string $expression) : array<string|int, ExpressionInterface|string>
Parameters
- $expression : ExpressionInterface|string
-
function argument