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

@ -3,7 +3,7 @@
Currently 6 aggregation functions are supported.
* `count() -> int`
* `count(distinct: bool = True) -> int`
* `exists() -> bool`
* `sum(columns) -> Any`
* `avg(columns) -> Any`
@ -12,19 +12,23 @@ Currently 6 aggregation functions are supported.
* `QuerysetProxy`
* `QuerysetProxy.count()` method
* `QuerysetProxy.count(distinct=True)` method
* `QuerysetProxy.exists()` method
* `QuerysetProxy.sum(columns)` method
* `QuerysetProxy.avg(columns)` method
* `QuerysetProxy.min(column)` method
* `QuerysetProxy.max(columns)` method
## 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
class Book(ormar.Model):
@ -84,7 +88,7 @@ Returns sum value of columns for rows matching the given criteria (applied with
You can pass one or many column names including related columns.
As of now each column passed is aggregated separately (so `sum(col1+col2)` is not possible,
As of now each column passed is aggregated separately (so `sum(col1+col2)` is not possible,
you can have `sum(col1, col2)` and later add 2 returned sums in python)
You cannot `sum` non numeric columns.
@ -138,7 +142,7 @@ Returns avg value of columns for rows matching the given criteria (applied with
You can pass one or many column names including related columns.
As of now each column passed is aggregated separately (so `sum(col1+col2)` is not possible,
As of now each column passed is aggregated separately (so `sum(col1+col2)` is not possible,
you can have `sum(col1, col2)` and later add 2 returned sums in python)
You cannot `avg` non numeric columns.
@ -193,7 +197,7 @@ Returns min value of columns for rows matching the given criteria (applied with
You can pass one or many column names including related columns.
As of now each column passed is aggregated separately (so `sum(col1+col2)` is not possible,
As of now each column passed is aggregated separately (so `sum(col1+col2)` is not possible,
you can have `sum(col1, col2)` and later add 2 returned sums in python)
If you aggregate on one column, the single value is directly returned as a result
@ -241,7 +245,7 @@ Returns min value of columns for rows matching the given criteria (applied with
You can pass one or many column names including related columns.
As of now each column passed is aggregated separately (so `sum(col1+col2)` is not possible,
As of now each column passed is aggregated separately (so `sum(col1+col2)` is not possible,
you can have `sum(col1, col2)` and later add 2 returned sums in python)
If you aggregate on one column, the single value is directly returned as a result
@ -292,7 +296,7 @@ select related etc related models directly from parent model.
Works exactly the same as [count](./#count) function above but allows you to select columns from related
objects from other side of the relation.
!!!tip
!!!tip
To read more about `QuerysetProxy` visit [querysetproxy][querysetproxy] section
### exists
@ -320,6 +324,5 @@ objects from other side of the relation.
Works exactly the same as [max](./#max) function above but allows you to select maximum of columns from related
objects from other side of the relation.
!!!tip
!!!tip
To read more about `QuerysetProxy` visit [querysetproxy][querysetproxy] section

View File

@ -8,7 +8,7 @@ and it's options.
Most of the methods are also available through many to many relations and on reverse
foreign key relations through `QuerysetProxy` interface.
!!!info
!!!info
To see which relations are supported and how to construct relations
visit [relations][relations].
@ -34,12 +34,12 @@ To read more about any specific section or function please refer to the details
* `Model.upsert()` method
* `Model.save_related()` method
* `QuerysetProxy`
* `QuerysetProxy.create(**kwargs)` method
* `QuerysetProxy.get_or_create(**kwargs)` method
* `QuerysetProxy.update_or_create(**kwargs)` method
!!!tip
To read more about any or all of those functions visit [create](./create.md) section.
@ -62,7 +62,7 @@ To read more about any specific section or function please refer to the details
* `QuerysetProxy.get_or_create(**kwargs)` method
* `QuerysetProxy.first()` method
* `QuerysetProxy.all(**kwargs)` method
!!!tip
To read more about any or all of those functions visit [read](./read.md) section.
@ -96,7 +96,7 @@ Instead of ormar models return raw data in form list of dictionaries or tuples.
* `QuerysetProxy`
* `QuerysetProxy.update_or_create(**kwargs)` method
!!!tip
To read more about any or all of those functions visit [update](./update.md) section.
@ -112,7 +112,7 @@ Instead of ormar models return raw data in form list of dictionaries or tuples.
* `QuerysetProxy`
* `QuerysetProxy.remove()` method
* `QuerysetProxy.clear()` method
!!!tip
To read more about any or all of those functions visit [delete](./delete.md) section.
@ -129,7 +129,7 @@ Instead of ormar models return raw data in form list of dictionaries or tuples.
* `QuerysetProxy`
* `QuerysetProxy.select_related(related: Union[List, str])` method
* `QuerysetProxy.prefetch_related(related: Union[List, str])` method
!!!tip
To read more about any or all of those functions visit [joins and subqueries](./joins-and-subqueries.md) section.
@ -152,7 +152,7 @@ Instead of ormar models return raw data in form list of dictionaries or tuples.
* `QuerysetProxy.get_or_none(**kwargs)` method
* `QuerysetProxy.get_or_create(**kwargs)` method
* `QuerysetProxy.all(**kwargs)` method
!!!tip
To read more about any or all of those functions visit [filtering and sorting](./filter-and-sort.md) section.
@ -165,7 +165,7 @@ Instead of ormar models return raw data in form list of dictionaries or tuples.
* `QuerysetProxy`
* `QuerysetProxy.fields(columns: Union[List, str, set, dict])` method
* `QuerysetProxy.exclude_fields(columns: Union[List, str, set, dict])` method
!!!tip
To read more about any or all of those functions visit [selecting columns](./select-columns.md) section.
@ -182,22 +182,22 @@ Instead of ormar models return raw data in form list of dictionaries or tuples.
* `QuerysetProxy.paginate(page: int)` method
* `QuerysetProxy.limit(limit_count: int)` method
* `QuerysetProxy.offset(offset: int)` method
!!!tip
To read more about any or all of those functions visit [pagination](./pagination-and-rows-number.md) section.
### [Aggregated functions](./aggregations.md)
* `count() -> int`
* `count(distinct: bool = True) -> int`
* `exists() -> bool`
* `QuerysetProxy`
* `QuerysetProxy.count()` method
* `QuerysetProxy.count(distinct=True)` method
* `QuerysetProxy.exists()` method
!!!tip
To read more about any or all of those functions visit [aggregations](./aggregations.md) section.
[relations]: ../relations/index.md