0 follower

Final Class Yiisoft\Db\Sqlite\Builder\ArrayMergeBuilder

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

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

(SELECT json_group_array(value) AS value FROM (
    SELECT value FROM json_each(operand1)
    UNION
    SELECT value FROM json_each(operand2)
))

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\Sqlite\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
{
    $selects = [];
    foreach ($expression->getOperands() as $operand) {
        $builtOperand = $this->buildOperand($operand, $params);
        $selects[] = "SELECT value FROM json_each($builtOperand)";
    }
    $unions = implode(' UNION ', $selects);
    if ($expression->getOrdered()) {
        $unions .= ' ORDER BY value';
    }
    return '(SELECT json_group_array(value) AS value FROM (' . $unions . '))';
}