ajout mergeQuery
This commit is contained in:
parent
007913ef86
commit
abada2401d
|
@ -148,17 +148,17 @@ class Capacitor implements ITransactor {
|
||||||
return $this->storage->_count($this->channel, $filter);
|
return $this->storage->_count($this->channel, $filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
function one($filter): ?array {
|
function one($filter, ?array $mergeQuery=null): ?array {
|
||||||
return $this->storage->_one($this->channel, $filter);
|
return $this->storage->_one($this->channel, $filter, $mergeQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
function all($filter): iterable {
|
function all($filter, ?array $mergeQuery=null): iterable {
|
||||||
return $this->storage->_all($this->channel, $filter);
|
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();
|
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 {
|
function delete($filter, $func=null, ?array $args=null): int {
|
||||||
|
|
|
@ -366,16 +366,16 @@ class CapacitorChannel {
|
||||||
return $this->capacitor->count($filter);
|
return $this->capacitor->count($filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
function one($filter): ?array {
|
function one($filter, ?array $mergeQuery=null): ?array {
|
||||||
return $this->capacitor->one($filter);
|
return $this->capacitor->one($filter, $mergeQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
function all($filter): iterable {
|
function all($filter, ?array $mergeQuery=null): iterable {
|
||||||
return $this->capacitor->all($filter);
|
return $this->capacitor->all($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 {
|
||||||
return $this->capacitor->each($filter, $func, $args, $updated);
|
return $this->capacitor->each($filter, $func, $args, $mergeQuery, $updated);
|
||||||
}
|
}
|
||||||
|
|
||||||
function delete($filter, $func=null, ?array $args=null): int {
|
function delete($filter, $func=null, ?array $args=null): int {
|
||||||
|
|
|
@ -436,20 +436,20 @@ EOT;
|
||||||
*
|
*
|
||||||
* si $filter n'est pas un tableau, il est transformé en ["id_" => $filter]
|
* 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");
|
if ($filter === null) throw ValueException::null("filter");
|
||||||
$this->_create($channel);
|
$this->_create($channel);
|
||||||
$this->verifixFilter($channel, $filter);
|
$this->verifixFilter($channel, $filter);
|
||||||
$row = $this->db()->one([
|
$row = $this->db()->one(cl::merge([
|
||||||
"select",
|
"select",
|
||||||
"from" => $channel->getTableName(),
|
"from" => $channel->getTableName(),
|
||||||
"where" => $filter,
|
"where" => $filter,
|
||||||
]);
|
], $mergeQuery));
|
||||||
return $this->unserialize($channel, $row);
|
return $this->unserialize($channel, $row);
|
||||||
}
|
}
|
||||||
|
|
||||||
function one(?string $channel, $filter): ?array {
|
function one(?string $channel, $filter, ?array $mergeQuery=null): ?array {
|
||||||
return $this->_one($this->getChannel($channel), $filter);
|
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]
|
* 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->_create($channel);
|
||||||
$this->verifixFilter($channel, $filter);
|
$this->verifixFilter($channel, $filter);
|
||||||
$rows = $this->db()->all([
|
$rows = $this->db()->all(cl::merge([
|
||||||
"select",
|
"select",
|
||||||
"from" => $channel->getTableName(),
|
"from" => $channel->getTableName(),
|
||||||
"where" => $filter,
|
"where" => $filter,
|
||||||
], null, $this->getPrimaryKeys($channel));
|
], $mergeQuery), null, $this->getPrimaryKeys($channel));
|
||||||
foreach ($rows as $key => $row) {
|
foreach ($rows as $key => $row) {
|
||||||
yield $key => $this->unserialize($channel, $row);
|
yield $key => $this->unserialize($channel, $row);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function all(?string $channel, $filter): iterable {
|
function all(?string $channel, $filter, $mergeQuery=null): iterable {
|
||||||
return $this->_all($this->getChannel($channel), $filter);
|
return $this->_all($this->getChannel($channel), $filter, $mergeQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -486,7 +486,7 @@ EOT;
|
||||||
* @param int $updated reçoit le nombre de lignes mises à jour
|
* @param int $updated reçoit le nombre de lignes mises à jour
|
||||||
* @return int le nombre de lignes parcourues
|
* @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);
|
$this->_create($channel);
|
||||||
if ($func === null) $func = CapacitorChannel::onEach;
|
if ($func === null) $func = CapacitorChannel::onEach;
|
||||||
func::ensure_func($func, $channel, $args);
|
func::ensure_func($func, $channel, $args);
|
||||||
|
@ -504,7 +504,7 @@ EOT;
|
||||||
$tableName = $channel->getTableName();
|
$tableName = $channel->getTableName();
|
||||||
try {
|
try {
|
||||||
$args ??= [];
|
$args ??= [];
|
||||||
foreach ($this->_all($channel, $filter) as $values) {
|
foreach ($this->_all($channel, $filter, $mergeQuery) as $values) {
|
||||||
$rowIds = $this->getRowIds($channel, $values);
|
$rowIds = $this->getRowIds($channel, $values);
|
||||||
$updates = func::_call($onEach, [$values["item"], $values, ...$args]);
|
$updates = func::_call($onEach, [$values["item"], $values, ...$args]);
|
||||||
if (is_array($updates) && $updates) {
|
if (is_array($updates) && $updates) {
|
||||||
|
@ -538,8 +538,8 @@ EOT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function each(?string $channel, $filter, $func=null, ?array $args=null, ?int &$updated=null): int {
|
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, $updated);
|
return $this->_each($this->getChannel($channel), $filter, $func, $args, $mergeQuery, $updated);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue