0 follower

Final Class Yiisoft\Db\Mysql\Builder\ArrayMergeBuilder

InheritanceYiisoft\Db\Mysql\Builder\ArrayMergeBuilder » Yiisoft\Db\Expression\Function\Builder\MultiOperandFunctionBuilder

Builds SQL expressions which merge arrays for {@see ArrayMerge} objects.

(SELECT JSON_ARRAYAGG(value) AS value FROM (
    SELECT value FROM JSON_TABLE(operand1, '$[*]' COLUMNS(value json PATH '$')) AS t
    UNION
    SELECT value FROM JSON_TABLE(operand2, '$[*]' COLUMNS(value json PATH '$')) AS t
) t)

Protected Methods

Hide inherited methods

Method Description Defined By
buildFromExpression() Builds a SQL expression which merges arrays from the given {@see ArrayMerge} object. Yiisoft\Db\Mysql\Builder\ArrayMergeBuilder

Constants

Hide inherited constants

Constant Value Description Defined By
DEFAULT_OPERAND_TYPE 'json' Yiisoft\Db\Mysql\Builder\ArrayMergeBuilder

Method Details

Hide inherited methods

buildFromExpression() protected method

Builds a SQL expression which merges arrays from the given {@see ArrayMerge} object.

protected string buildFromExpression ( \Yiisoft\Db\Expression\Function\ArrayMerge $expression, array &$params )
$expression \Yiisoft\Db\Expression\Function\ArrayMerge

The expression to build.

$params array

The parameters to bind.

return string

The SQL expression.

                protected function buildFromExpression(MultiOperandFunction $expression, array &$params): string
{
    $operandType = $this->buildOperandType($expression->getType());
    $selects = [];
    foreach ($expression->getOperands() as $operand) {
        $builtOperand = $this->buildOperand($operand, $params);
        $selects[] = "SELECT value FROM JSON_TABLE($builtOperand, '$[*]' COLUMNS(value $operandType PATH '$')) AS t";
    }
    $unions = implode(' UNION ', $selects);
    if ($expression->getOrdered()) {
        $unions .= ' ORDER BY value';
    }
    return '(SELECT JSON_ARRAYAGG(value) AS value FROM (' . $unions . ') AS t)';
}