support distinc dans _select
This commit is contained in:
parent
1f14faf08c
commit
2c45aa677a
@ -185,19 +185,15 @@ 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);
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ class _select extends _common {
|
|||||||
const SCHEMA = [
|
const SCHEMA = [
|
||||||
"prefix" => "?string",
|
"prefix" => "?string",
|
||||||
"schema" => "?array",
|
"schema" => "?array",
|
||||||
|
"distinct" => "bool",
|
||||||
"cols" => "?array",
|
"cols" => "?array",
|
||||||
"col_prefix" => "?string",
|
"col_prefix" => "?string",
|
||||||
"from" => "?string",
|
"from" => "?string",
|
||||||
@ -45,8 +46,16 @@ class _select extends _common {
|
|||||||
if (($prefix = $query["prefix"] ?? null) !== null) $sql[] = $prefix;
|
if (($prefix = $query["prefix"] ?? null) !== null) $sql[] = $prefix;
|
||||||
|
|
||||||
## select
|
## select
|
||||||
self::consume('(select(?:\s*distinct)?)\s*', $tmpsql, $ms);
|
self::consume('(select(?:\s*(distinct))?)\s*', $tmpsql, $ms);
|
||||||
$sql[] = $ms[1];
|
$sql[] = $ms[1];
|
||||||
|
if (($ms[2] ?? null) !== null) {
|
||||||
|
# ne pas le rajouter de nouveau ci-dessous
|
||||||
|
$distinct = false;
|
||||||
|
} else $distinct = null;
|
||||||
|
|
||||||
|
## distinct
|
||||||
|
$distinct ??= $query["distinct"] ?? false;
|
||||||
|
if ($distinct) $sql[] = "distinct";
|
||||||
|
|
||||||
## cols
|
## cols
|
||||||
$usercols = [];
|
$usercols = [];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user