Fix collerek/ormar#588 documentation for distinct keyword to count method

This commit is contained in:
haydeec1
2022-03-17 14:09:46 -04:00
parent 606a592038
commit 11e6f1eecd
7 changed files with 84 additions and 67 deletions

View File

@ -601,7 +601,7 @@ metadata.drop_all(engine)
* `prefetch_related(related: Union[List, str]) -> QuerySet` * `prefetch_related(related: Union[List, str]) -> QuerySet`
* `limit(limit_count: int) -> QuerySet` * `limit(limit_count: int) -> QuerySet`
* `offset(offset: int) -> QuerySet` * `offset(offset: int) -> QuerySet`
* `count() -> int` * `count(distinct: bool = True) -> int`
* `exists() -> bool` * `exists() -> bool`
* `max(columns: List[str]) -> Any` * `max(columns: List[str]) -> Any`
* `min(columns: List[str]) -> Any` * `min(columns: List[str]) -> Any`

View File

@ -499,11 +499,19 @@ Returns a bool value to confirm if there are rows matching the given criteria
#### count #### count
```python ```python
| async count() -> int | async count(distinct: bool = True) -> int
``` ```
Returns number of rows matching the given criteria Returns number of rows matching the given criteria
(applied with `filter` and `exclude` if set before). (applied with `filter` and `exclude` if set before).
If `distinct` is `True` (the default), this will return the number of primary rows selected. If `False`,
the count will be the total number of rows returned
(including extra rows for `one-to-many` or `many-to-many` left `select_related` table joins).
`False` is the legacy (buggy) behavior for workflows that depend on it.
**Arguments**:
- `distinct` (`bool`): flag if the primary table rows should be distinct or not
**Returns**: **Returns**:
@ -865,4 +873,3 @@ Bulk operations do not send signals.
- `objects` (`List[Model]`): list of ormar models - `objects` (`List[Model]`): list of ormar models
- `columns` (`List[str]`): list of columns to update - `columns` (`List[str]`): list of columns to update

View File

@ -150,14 +150,22 @@ Actual call delegated to QuerySet.
#### count #### count
```python ```python
| async count() -> int | async count(distinct: bool = True) -> int
``` ```
Returns number of rows matching the given criteria Returns number of rows matching the given criteria
(applied with `filter` and `exclude` if set before). (applied with `filter` and `exclude` if set before).
If `distinct` is `True` (the default), this will return the number of primary rows selected. If `False`,
the count will be the total number of rows returned
(including extra rows for `one-to-many` or `many-to-many` left `select_related` table joins).
`False` is the legacy (buggy) behavior for workflows that depend on it.
Actual call delegated to QuerySet. Actual call delegated to QuerySet.
**Arguments**:
- `distinct` (`bool`): flag if the primary table rows should be distinct or not
**Returns**: **Returns**:
`int`: number of rows `int`: number of rows
@ -773,4 +781,3 @@ Actual call delegated to QuerySet.
**Returns**: **Returns**:
`QuerysetProxy`: QuerysetProxy `QuerysetProxy`: QuerysetProxy

View File

@ -610,7 +610,7 @@ metadata.drop_all(engine)
* `prefetch_related(related: Union[List, str]) -> QuerySet` * `prefetch_related(related: Union[List, str]) -> QuerySet`
* `limit(limit_count: int) -> QuerySet` * `limit(limit_count: int) -> QuerySet`
* `offset(offset: int) -> QuerySet` * `offset(offset: int) -> QuerySet`
* `count() -> int` * `count(distinct: bool = True) -> int`
* `exists() -> bool` * `exists() -> bool`
* `max(columns: List[str]) -> Any` * `max(columns: List[str]) -> Any`
* `min(columns: List[str]) -> Any` * `min(columns: List[str]) -> Any`

View File

@ -3,7 +3,7 @@
Currently 6 aggregation functions are supported. Currently 6 aggregation functions are supported.
* `count() -> int` * `count(distinct: bool = True) -> int`
* `exists() -> bool` * `exists() -> bool`
* `sum(columns) -> Any` * `sum(columns) -> Any`
* `avg(columns) -> Any` * `avg(columns) -> Any`
@ -12,7 +12,7 @@ Currently 6 aggregation functions are supported.
* `QuerysetProxy` * `QuerysetProxy`
* `QuerysetProxy.count()` method * `QuerysetProxy.count(distinct=True)` method
* `QuerysetProxy.exists()` method * `QuerysetProxy.exists()` method
* `QuerysetProxy.sum(columns)` method * `QuerysetProxy.sum(columns)` method
* `QuerysetProxy.avg(columns)` method * `QuerysetProxy.avg(columns)` method
@ -22,9 +22,13 @@ Currently 6 aggregation functions are supported.
## count ## count
`count() -> int` `count(distinct: bool = True) -> int`
Returns number of rows matching the given criteria (i.e. applied with `filter` and `exclude`) Returns number of rows matching the given criteria (i.e. applied with `filter` and `exclude`).
If `distinct` is `True` (the default), this will return the number of primary rows selected. If `False`,
the count will be the total number of rows returned
(including extra rows for `one-to-many` or `many-to-many` left `select_related` table joins).
`False` is the legacy (buggy) behavior for workflows that depend on it.
```python ```python
class Book(ormar.Model): class Book(ormar.Model):
@ -322,4 +326,3 @@ objects from other side of the relation.
!!!tip !!!tip
To read more about `QuerysetProxy` visit [querysetproxy][querysetproxy] section To read more about `QuerysetProxy` visit [querysetproxy][querysetproxy] section

View File

@ -188,12 +188,12 @@ Instead of ormar models return raw data in form list of dictionaries or tuples.
### [Aggregated functions](./aggregations.md) ### [Aggregated functions](./aggregations.md)
* `count() -> int` * `count(distinct: bool = True) -> int`
* `exists() -> bool` * `exists() -> bool`
* `QuerysetProxy` * `QuerysetProxy`
* `QuerysetProxy.count()` method * `QuerysetProxy.count(distinct=True)` method
* `QuerysetProxy.exists()` method * `QuerysetProxy.exists()` method
!!!tip !!!tip

View File

@ -274,7 +274,7 @@ With exclude_fields() you can select subset of model columns that will be exclud
### count ### count
`count() -> int` `count(distinct: bool = True) -> int`
Returns number of rows matching the given criteria (i.e. applied with filter and exclude) Returns number of rows matching the given criteria (i.e. applied with filter and exclude)