diff --git a/src/db/Capacitor.php b/src/db/Capacitor.php index b7c7155..7f321df 100644 --- a/src/db/Capacitor.php +++ b/src/db/Capacitor.php @@ -148,17 +148,17 @@ class Capacitor implements ITransactor { return $this->storage->_count($this->channel, $filter); } - function one($filter): ?array { - return $this->storage->_one($this->channel, $filter); + function one($filter, ?array $mergeQuery=null): ?array { + return $this->storage->_one($this->channel, $filter, $mergeQuery); } - function all($filter): iterable { - return $this->storage->_all($this->channel, $filter); + function all($filter, ?array $mergeQuery=null): iterable { + return $this->storage->_all($this->channel, $filter, $mergeQuery); } - function each($filter, $func=null, ?array $args=null, ?int &$updated=null): int { + function each($filter, $func=null, ?array $args=null, ?array $mergeQuery=null, ?int &$updated=null): int { if ($this->subChannels !== null) $this->beginTransaction(); - return $this->storage->_each($this->channel, $filter, $func, $args, $updated); + return $this->storage->_each($this->channel, $filter, $func, $args, $mergeQuery, $updated); } function delete($filter, $func=null, ?array $args=null): int { diff --git a/src/db/CapacitorChannel.php b/src/db/CapacitorChannel.php index ae62d82..94b360e 100644 --- a/src/db/CapacitorChannel.php +++ b/src/db/CapacitorChannel.php @@ -366,16 +366,16 @@ class CapacitorChannel { return $this->capacitor->count($filter); } - function one($filter): ?array { - return $this->capacitor->one($filter); + function one($filter, ?array $mergeQuery=null): ?array { + return $this->capacitor->one($filter, $mergeQuery); } - function all($filter): iterable { - return $this->capacitor->all($filter); + function all($filter, ?array $mergeQuery=null): iterable { + return $this->capacitor->all($filter, $mergeQuery); } - function each($filter, $func=null, ?array $args=null, ?int &$updated=null): int { - return $this->capacitor->each($filter, $func, $args, $updated); + function each($filter, $func=null, ?array $args=null, ?array $mergeQuery=null, ?int &$updated=null): int { + return $this->capacitor->each($filter, $func, $args, $mergeQuery, $updated); } function delete($filter, $func=null, ?array $args=null): int { diff --git a/src/db/CapacitorStorage.php b/src/db/CapacitorStorage.php index 1ee00fc..e61a891 100644 --- a/src/db/CapacitorStorage.php +++ b/src/db/CapacitorStorage.php @@ -436,20 +436,20 @@ EOT; * * si $filter n'est pas un tableau, il est transformé en ["id_" => $filter] */ - function _one(CapacitorChannel $channel, $filter): ?array { + function _one(CapacitorChannel $channel, $filter, ?array $mergeQuery=null): ?array { if ($filter === null) throw ValueException::null("filter"); $this->_create($channel); $this->verifixFilter($channel, $filter); - $row = $this->db()->one([ + $row = $this->db()->one(cl::merge([ "select", "from" => $channel->getTableName(), "where" => $filter, - ]); + ], $mergeQuery)); return $this->unserialize($channel, $row); } - function one(?string $channel, $filter): ?array { - return $this->_one($this->getChannel($channel), $filter); + function one(?string $channel, $filter, ?array $mergeQuery=null): ?array { + return $this->_one($this->getChannel($channel), $filter, $mergeQuery); } /** @@ -457,21 +457,21 @@ EOT; * * si $filter n'est pas un tableau, il est transformé en ["id_" => $filter] */ - function _all(CapacitorChannel $channel, $filter): iterable { + function _all(CapacitorChannel $channel, $filter, ?array $mergeQuery=null): iterable { $this->_create($channel); $this->verifixFilter($channel, $filter); - $rows = $this->db()->all([ + $rows = $this->db()->all(cl::merge([ "select", "from" => $channel->getTableName(), "where" => $filter, - ], null, $this->getPrimaryKeys($channel)); + ], $mergeQuery), null, $this->getPrimaryKeys($channel)); foreach ($rows as $key => $row) { yield $key => $this->unserialize($channel, $row); } } - function all(?string $channel, $filter): iterable { - return $this->_all($this->getChannel($channel), $filter); + function all(?string $channel, $filter, $mergeQuery=null): iterable { + return $this->_all($this->getChannel($channel), $filter, $mergeQuery); } /** @@ -486,7 +486,7 @@ EOT; * @param int $updated reçoit le nombre de lignes mises à jour * @return int le nombre de lignes parcourues */ - function _each(CapacitorChannel $channel, $filter, $func, ?array $args, ?int &$updated=null): int { + function _each(CapacitorChannel $channel, $filter, $func, ?array $args, ?array $mergeQuery=null, ?int &$updated=null): int { $this->_create($channel); if ($func === null) $func = CapacitorChannel::onEach; func::ensure_func($func, $channel, $args); @@ -504,7 +504,7 @@ EOT; $tableName = $channel->getTableName(); try { $args ??= []; - foreach ($this->_all($channel, $filter) as $values) { + foreach ($this->_all($channel, $filter, $mergeQuery) as $values) { $rowIds = $this->getRowIds($channel, $values); $updates = func::_call($onEach, [$values["item"], $values, ...$args]); if (is_array($updates) && $updates) { @@ -538,8 +538,8 @@ EOT; } } - function each(?string $channel, $filter, $func=null, ?array $args=null, ?int &$updated=null): int { - return $this->_each($this->getChannel($channel), $filter, $func, $args, $updated); + function each(?string $channel, $filter, $func=null, ?array $args=null, ?array $mergeQuery=null, ?int &$updated=null): int { + return $this->_each($this->getChannel($channel), $filter, $func, $args, $mergeQuery, $updated); } /**