- Fixed the missing DISTINCT keyword while rendering select()

- Added a fragment remover in Repository
This commit is contained in:
Dave M. 2021-03-01 16:10:15 +00:00
parent 8f9332fbad
commit e7d5d5965b
2 changed files with 17 additions and 1 deletions

View File

@ -48,6 +48,7 @@ class Select extends Fragment {
return $this->renderSegments([ return $this->renderSegments([
( $this->union ? 'UNION' : false ), ( $this->union ? 'UNION' : false ),
static::SQL_TOKEN, static::SQL_TOKEN,
( $this->distinct ? 'DISTINCT' : false ),
( $this->top ? sprintf('TOP (%s)', $this->top) : false ), ( $this->top ? sprintf('TOP (%s)', $this->top) : false ),
implode(', ', $this->fields) implode(', ', $this->fields)
]); ]);

View File

@ -271,6 +271,13 @@ class Repository
} }
} }
public function removeQueryFragment(Query\Fragment $fragment) : self
{
$this->queryBuilder->removeFragment($fragment);
return $this;
}
public function select(/*array|Stringable*/ $fields) : self public function select(/*array|Stringable*/ $fields) : self
{ {
$this->queryBuilder->select($fields); $this->queryBuilder->select($fields);
@ -278,6 +285,14 @@ class Repository
return $this; return $this;
} }
public function distinct(/*array|Stringable*/ $fields) : self
{
$this->queryBuilder->select($fields);
$this->queryBuilder->getFragment(Query\Select::class)->distinct = true;
return $this;
}
public function insert(array $fieldlist, string $table, string $alias, ? string $schema) : self public function insert(array $fieldlist, string $table, string $alias, ? string $schema) : self
{ {
$this->queryBuilder->insert($fieldlist, $this->escapeTable($table), $alias, $this->escapedDatabase(), $schema); $this->queryBuilder->insert($fieldlist, $this->escapeTable($table), $alias, $this->escapedDatabase(), $schema);