dbAll() support distinct

This commit is contained in:
Jephté Clain 2025-07-07 21:42:25 +04:00
parent aeaf3eb1dd
commit 1f14faf08c

View File

@ -1,6 +1,7 @@
<?php <?php
namespace nulib\db; namespace nulib\db;
use nulib\A;
use nulib\cl; use nulib\cl;
use nulib\php\func; use nulib\php\func;
use nulib\ValueException; use nulib\ValueException;
@ -184,15 +185,19 @@ class Capacitor implements ITransactor {
function dbAll(array $query, ?array $params=null): iterable { function dbAll(array $query, ?array $params=null): iterable {
$primaryKeys = $this->channel->getPrimaryKeys(); $primaryKeys = $this->channel->getPrimaryKeys();
$select = "select";
if (A::pop($params, "distinct")) $select .= " distinct";
return $this->storage->db()->all(cl::merge([ return $this->storage->db()->all(cl::merge([
"select", $select,
"from" => $this->getTableName(), "from" => $this->getTableName(),
], $query), $params, $primaryKeys); ], $query), $params, $primaryKeys);
} }
function dbOne(array $query, ?array $params=null): ?array { function dbOne(array $query, ?array $params=null): ?array {
$select = "select";
if (A::pop($params, "distinct")) $select .= " distinct";
return $this->storage->db()->one(cl::merge([ return $this->storage->db()->one(cl::merge([
"select", $select,
"from" => $this->getTableName(), "from" => $this->getTableName(),
], $query), $params); ], $query), $params);
} }