Fr3nch13/CakePHP Utilities

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
FunctionExpression

aggregate()

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
AggregateExpression

coalesce()

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
FunctionExpression

concat()

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
FunctionExpression

dateAdd()

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
FunctionExpression

dateDiff()

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
FunctionExpression

datePart()

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
FunctionExpression

extract()

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
FunctionExpression

lag()

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
AggregateExpression

lead()

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
AggregateExpression

now()

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
FunctionExpression

        
On this page

Search results