From 792e1ff96514d3f859379b74c7f878cdb9a9b4c9 Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Wed, 25 Jun 2025 17:14:19 +0400 Subject: [PATCH] ajout dbAll, dbOne --- php/src/db/Capacitor.php | 20 ++++++++++++++++++-- php/src/db/CapacitorChannel.php | 13 +++++++++++-- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/php/src/db/Capacitor.php b/php/src/db/Capacitor.php index 8c62b42..d09f2e0 100644 --- a/php/src/db/Capacitor.php +++ b/php/src/db/Capacitor.php @@ -182,11 +182,27 @@ class Capacitor implements ITransactor { return $this->storage->_delete($this->channel, $filter, $func, $args); } - function dbUpdate(array $update) { + function dbAll(array $query, ?array $params=null): iterable { + $primaryKeys = $this->channel->getPrimaryKeys(); + return $this->storage->db()->all(cl::merge([ + "select", + "from" => $this->getTableName(), + ], $query), $params, $primaryKeys); + } + + function dbOne(array $query, ?array $params=null): ?array { + return $this->storage->db()->one(cl::merge([ + "select", + "from" => $this->getTableName(), + ], $query), $params); + } + + /** @return int|false */ + function dbUpdate(array $query, ?array $params=null) { return $this->storage->db()->exec(cl::merge([ "update", "table" => $this->getTableName(), - ], $update)); + ], $query), $params); } function close(): void { diff --git a/php/src/db/CapacitorChannel.php b/php/src/db/CapacitorChannel.php index 7e8ff44..fa1fce6 100644 --- a/php/src/db/CapacitorChannel.php +++ b/php/src/db/CapacitorChannel.php @@ -508,8 +508,17 @@ class CapacitorChannel implements ITransactor { return $this->capacitor->delete($filter, $func, $args); } - function dbUpdate(array $update) { - return $this->capacitor->dbUpdate($update); + function dbAll(array $query, ?array $params=null): iterable { + return $this->capacitor->dbAll($query, $params); + } + + function dbOne(array $query, ?array $params=null): ?array { + return $this->capacitor->dbOne($query, $params); + } + + /** @return int|false */ + function dbUpdate(array $query, ?array $params=null) { + return $this->capacitor->dbUpdate($query, $params); } function close(): void {