mini\Database\VirtualDatabase::createAggregate() Method

public

Signature

public function createAggregate(string $name, callable $stepCallback, callable $finalCallback, int $argCount = -1): bool

Parameters

Name Type Default Description
$name string required Documentation missing
$stepCallback callable required Documentation missing
$finalCallback callable required Documentation missing
$argCount int -1 Documentation missing

Returns

bool

Documentation

Register a custom aggregate function

Similar to SQLite3::createAggregate. The step callback is called for each row with the current context and argument values. The final callback is called after all rows to produce the result.

// Example: Custom GROUP_CONCAT
$vdb->createAggregate(
    'group_concat',
    function(&$context, $value) {
        $context[] = $value;
    },
    function(&$context) {
        return implode(',', $context ?? []);
    },
    1
);

Source

src/Database/VirtualDatabase.php:152-164