ajout mergeQuery

This commit is contained in:
Jephté Clain 2024-07-12 02:44:18 +04:00
parent 007913ef86
commit abada2401d
3 changed files with 26 additions and 26 deletions

View File

@ -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 {

View File

@ -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 {

View File

@ -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);
}
/**