fix isnull typo and formatting
This commit is contained in:
@ -1,6 +1,115 @@
|
||||
<a name="queryset.clause"></a>
|
||||
# queryset.clause
|
||||
|
||||
<a name="queryset.clause.FilterGroup"></a>
|
||||
## FilterGroup Objects
|
||||
|
||||
```python
|
||||
class FilterGroup()
|
||||
```
|
||||
|
||||
Filter groups are used in complex queries condition to group and and or
|
||||
clauses in where condition
|
||||
|
||||
<a name="queryset.clause.FilterGroup.resolve"></a>
|
||||
#### resolve
|
||||
|
||||
```python
|
||||
| resolve(model_cls: Type["Model"], select_related: List = None, filter_clauses: List = None) -> Tuple[List[FilterAction], List[str]]
|
||||
```
|
||||
|
||||
Resolves the FilterGroups actions to use proper target model, replace
|
||||
complex relation prefixes if needed and nested groups also resolved.
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `model_cls (Type["Model"])`: model from which the query is run
|
||||
- `select_related (List[str])`: list of models to join
|
||||
- `filter_clauses (List[FilterAction])`: list of filter conditions
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(Tuple[List[FilterAction], List[str]])`: list of filter conditions and select_related list
|
||||
|
||||
<a name="queryset.clause.FilterGroup._iter"></a>
|
||||
#### \_iter
|
||||
|
||||
```python
|
||||
| _iter() -> Generator
|
||||
```
|
||||
|
||||
Iterates all actions in a tree
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(Generator)`: generator yielding from own actions and nested groups
|
||||
|
||||
<a name="queryset.clause.FilterGroup._get_text_clauses"></a>
|
||||
#### \_get\_text\_clauses
|
||||
|
||||
```python
|
||||
| _get_text_clauses() -> List[sqlalchemy.sql.expression.TextClause]
|
||||
```
|
||||
|
||||
Helper to return list of text queries from actions and nested groups
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(List[sqlalchemy.sql.elements.TextClause])`: list of text queries from actions and nested groups
|
||||
|
||||
<a name="queryset.clause.FilterGroup.get_text_clause"></a>
|
||||
#### get\_text\_clause
|
||||
|
||||
```python
|
||||
| get_text_clause() -> sqlalchemy.sql.expression.TextClause
|
||||
```
|
||||
|
||||
Returns all own actions and nested groups conditions compiled and joined
|
||||
inside parentheses.
|
||||
Escapes characters if it's required.
|
||||
Substitutes values of the models if value is a ormar Model with its pk value.
|
||||
Compiles the clause.
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(sqlalchemy.sql.elements.TextClause)`: complied and escaped clause
|
||||
|
||||
<a name="queryset.clause.or_"></a>
|
||||
#### or\_
|
||||
|
||||
```python
|
||||
or_(*args: FilterGroup, **kwargs: Any) -> FilterGroup
|
||||
```
|
||||
|
||||
Construct or filter from nested groups and keyword arguments
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `args (Tuple[FilterGroup])`: nested filter groups
|
||||
- `kwargs (Any)`: fields names and proper value types
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(ormar.queryset.clause.FilterGroup)`: FilterGroup ready to be resolved
|
||||
|
||||
<a name="queryset.clause.and_"></a>
|
||||
#### and\_
|
||||
|
||||
```python
|
||||
and_(*args: FilterGroup, **kwargs: Any) -> FilterGroup
|
||||
```
|
||||
|
||||
Construct and filter from nested groups and keyword arguments
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `args (Tuple[FilterGroup])`: nested filter groups
|
||||
- `kwargs (Any)`: fields names and proper value types
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(ormar.queryset.clause.FilterGroup)`: FilterGroup ready to be resolved
|
||||
|
||||
<a name="queryset.clause.QueryClause"></a>
|
||||
## QueryClause Objects
|
||||
|
||||
@ -14,7 +123,7 @@ Constructs FilterActions from strings passed as arguments
|
||||
#### prepare\_filter
|
||||
|
||||
```python
|
||||
| prepare_filter(**kwargs: Any) -> Tuple[List[FilterAction], List[str]]
|
||||
| prepare_filter(_own_only: bool = False, **kwargs: Any) -> Tuple[List[FilterAction], List[str]]
|
||||
```
|
||||
|
||||
Main external access point that processes the clauses into sqlalchemy text
|
||||
@ -23,6 +132,7 @@ mentioned in select_related strings but not included in select_related.
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `_own_only ()`:
|
||||
- `kwargs (Any)`: key, value pair with column names and values
|
||||
|
||||
**Returns**:
|
||||
@ -33,7 +143,7 @@ mentioned in select_related strings but not included in select_related.
|
||||
#### \_populate\_filter\_clauses
|
||||
|
||||
```python
|
||||
| _populate_filter_clauses(**kwargs: Any) -> Tuple[List[FilterAction], List[str]]
|
||||
| _populate_filter_clauses(_own_only: bool, **kwargs: Any) -> Tuple[List[FilterAction], List[str]]
|
||||
```
|
||||
|
||||
Iterates all clauses and extracts used operator and field from related
|
||||
@ -104,3 +214,16 @@ present in alias_manager.
|
||||
|
||||
`(List[FilterAction])`: list of actions with aliases changed if needed
|
||||
|
||||
<a name="queryset.clause.QueryClause._verify_prefix_and_switch"></a>
|
||||
#### \_verify\_prefix\_and\_switch
|
||||
|
||||
```python
|
||||
| _verify_prefix_and_switch(action: "FilterAction") -> None
|
||||
```
|
||||
|
||||
Helper to switch prefix to complex relation one if required
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `action (ormar.queryset.actions.filter_action.FilterAction)`: action to switch prefix in
|
||||
|
||||
|
||||
359
docs/api/query-set/field-accessor.md
Normal file
359
docs/api/query-set/field-accessor.md
Normal file
@ -0,0 +1,359 @@
|
||||
<a name="queryset.field_accessor"></a>
|
||||
# queryset.field\_accessor
|
||||
|
||||
<a name="queryset.field_accessor.FieldAccessor"></a>
|
||||
## FieldAccessor Objects
|
||||
|
||||
```python
|
||||
class FieldAccessor()
|
||||
```
|
||||
|
||||
Helper to access ormar fields directly from Model class also for nested
|
||||
models attributes.
|
||||
|
||||
<a name="queryset.field_accessor.FieldAccessor.__bool__"></a>
|
||||
#### \_\_bool\_\_
|
||||
|
||||
```python
|
||||
| __bool__() -> bool
|
||||
```
|
||||
|
||||
Hack to avoid pydantic name check from parent model, returns false
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(bool)`: False
|
||||
|
||||
<a name="queryset.field_accessor.FieldAccessor.__getattr__"></a>
|
||||
#### \_\_getattr\_\_
|
||||
|
||||
```python
|
||||
| __getattr__(item: str) -> Any
|
||||
```
|
||||
|
||||
Accessor return new accessor for each field and nested models.
|
||||
Thanks to that operator overload is possible to use in filter.
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `item (str)`: attribute name
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(ormar.queryset.field_accessor.FieldAccessor)`: FieldAccessor for field or nested model
|
||||
|
||||
<a name="queryset.field_accessor.FieldAccessor.__eq__"></a>
|
||||
#### \_\_eq\_\_
|
||||
|
||||
```python
|
||||
| __eq__(other: Any) -> FilterGroup
|
||||
```
|
||||
|
||||
overloaded to work as sql `column = <VALUE>`
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `other (str)`: value to check agains operator
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(ormar.queryset.clause.FilterGroup)`: FilterGroup for operator
|
||||
|
||||
<a name="queryset.field_accessor.FieldAccessor.__ge__"></a>
|
||||
#### \_\_ge\_\_
|
||||
|
||||
```python
|
||||
| __ge__(other: Any) -> FilterGroup
|
||||
```
|
||||
|
||||
overloaded to work as sql `column >= <VALUE>`
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `other (str)`: value to check agains operator
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(ormar.queryset.clause.FilterGroup)`: FilterGroup for operator
|
||||
|
||||
<a name="queryset.field_accessor.FieldAccessor.__gt__"></a>
|
||||
#### \_\_gt\_\_
|
||||
|
||||
```python
|
||||
| __gt__(other: Any) -> FilterGroup
|
||||
```
|
||||
|
||||
overloaded to work as sql `column > <VALUE>`
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `other (str)`: value to check agains operator
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(ormar.queryset.clause.FilterGroup)`: FilterGroup for operator
|
||||
|
||||
<a name="queryset.field_accessor.FieldAccessor.__le__"></a>
|
||||
#### \_\_le\_\_
|
||||
|
||||
```python
|
||||
| __le__(other: Any) -> FilterGroup
|
||||
```
|
||||
|
||||
overloaded to work as sql `column <= <VALUE>`
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `other (str)`: value to check agains operator
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(ormar.queryset.clause.FilterGroup)`: FilterGroup for operator
|
||||
|
||||
<a name="queryset.field_accessor.FieldAccessor.__lt__"></a>
|
||||
#### \_\_lt\_\_
|
||||
|
||||
```python
|
||||
| __lt__(other: Any) -> FilterGroup
|
||||
```
|
||||
|
||||
overloaded to work as sql `column < <VALUE>`
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `other (str)`: value to check agains operator
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(ormar.queryset.clause.FilterGroup)`: FilterGroup for operator
|
||||
|
||||
<a name="queryset.field_accessor.FieldAccessor.__mod__"></a>
|
||||
#### \_\_mod\_\_
|
||||
|
||||
```python
|
||||
| __mod__(other: Any) -> FilterGroup
|
||||
```
|
||||
|
||||
overloaded to work as sql `column LIKE '%<VALUE>%'`
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `other (str)`: value to check agains operator
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(ormar.queryset.clause.FilterGroup)`: FilterGroup for operator
|
||||
|
||||
<a name="queryset.field_accessor.FieldAccessor.__lshift__"></a>
|
||||
#### \_\_lshift\_\_
|
||||
|
||||
```python
|
||||
| __lshift__(other: Any) -> FilterGroup
|
||||
```
|
||||
|
||||
overloaded to work as sql `column IN (<VALUE1>, <VALUE2>,...)`
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `other (str)`: value to check agains operator
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(ormar.queryset.clause.FilterGroup)`: FilterGroup for operator
|
||||
|
||||
<a name="queryset.field_accessor.FieldAccessor.__rshift__"></a>
|
||||
#### \_\_rshift\_\_
|
||||
|
||||
```python
|
||||
| __rshift__(other: Any) -> FilterGroup
|
||||
```
|
||||
|
||||
overloaded to work as sql `column IS NULL`
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `other (str)`: value to check agains operator
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(ormar.queryset.clause.FilterGroup)`: FilterGroup for operator
|
||||
|
||||
<a name="queryset.field_accessor.FieldAccessor.in_"></a>
|
||||
#### in\_
|
||||
|
||||
```python
|
||||
| in_(other: Any) -> FilterGroup
|
||||
```
|
||||
|
||||
works as sql `column IN (<VALUE1>, <VALUE2>,...)`
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `other (str)`: value to check agains operator
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(ormar.queryset.clause.FilterGroup)`: FilterGroup for operator
|
||||
|
||||
<a name="queryset.field_accessor.FieldAccessor.iexact"></a>
|
||||
#### iexact
|
||||
|
||||
```python
|
||||
| iexact(other: Any) -> FilterGroup
|
||||
```
|
||||
|
||||
works as sql `column = <VALUE>` case-insensitive
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `other (str)`: value to check agains operator
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(ormar.queryset.clause.FilterGroup)`: FilterGroup for operator
|
||||
|
||||
<a name="queryset.field_accessor.FieldAccessor.contains"></a>
|
||||
#### contains
|
||||
|
||||
```python
|
||||
| contains(other: Any) -> FilterGroup
|
||||
```
|
||||
|
||||
works as sql `column LIKE '%<VALUE>%'`
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `other (str)`: value to check agains operator
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(ormar.queryset.clause.FilterGroup)`: FilterGroup for operator
|
||||
|
||||
<a name="queryset.field_accessor.FieldAccessor.icontains"></a>
|
||||
#### icontains
|
||||
|
||||
```python
|
||||
| icontains(other: Any) -> FilterGroup
|
||||
```
|
||||
|
||||
works as sql `column LIKE '%<VALUE>%'` case-insensitive
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `other (str)`: value to check agains operator
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(ormar.queryset.clause.FilterGroup)`: FilterGroup for operator
|
||||
|
||||
<a name="queryset.field_accessor.FieldAccessor.startswith"></a>
|
||||
#### startswith
|
||||
|
||||
```python
|
||||
| startswith(other: Any) -> FilterGroup
|
||||
```
|
||||
|
||||
works as sql `column LIKE '<VALUE>%'`
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `other (str)`: value to check agains operator
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(ormar.queryset.clause.FilterGroup)`: FilterGroup for operator
|
||||
|
||||
<a name="queryset.field_accessor.FieldAccessor.istartswith"></a>
|
||||
#### istartswith
|
||||
|
||||
```python
|
||||
| istartswith(other: Any) -> FilterGroup
|
||||
```
|
||||
|
||||
works as sql `column LIKE '%<VALUE>'` case-insensitive
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `other (str)`: value to check agains operator
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(ormar.queryset.clause.FilterGroup)`: FilterGroup for operator
|
||||
|
||||
<a name="queryset.field_accessor.FieldAccessor.endswith"></a>
|
||||
#### endswith
|
||||
|
||||
```python
|
||||
| endswith(other: Any) -> FilterGroup
|
||||
```
|
||||
|
||||
works as sql `column LIKE '%<VALUE>'`
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `other (str)`: value to check agains operator
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(ormar.queryset.clause.FilterGroup)`: FilterGroup for operator
|
||||
|
||||
<a name="queryset.field_accessor.FieldAccessor.iendswith"></a>
|
||||
#### iendswith
|
||||
|
||||
```python
|
||||
| iendswith(other: Any) -> FilterGroup
|
||||
```
|
||||
|
||||
works as sql `column LIKE '%<VALUE>'` case-insensitive
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `other (str)`: value to check agains operator
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(ormar.queryset.clause.FilterGroup)`: FilterGroup for operator
|
||||
|
||||
<a name="queryset.field_accessor.FieldAccessor.isnull"></a>
|
||||
#### isnull
|
||||
|
||||
```python
|
||||
| isnull(other: Any) -> FilterGroup
|
||||
```
|
||||
|
||||
works as sql `column IS NULL` or `IS NOT NULL`
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `other (str)`: value to check agains operator
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(ormar.queryset.clause.FilterGroup)`: FilterGroup for operator
|
||||
|
||||
<a name="queryset.field_accessor.FieldAccessor.asc"></a>
|
||||
#### asc
|
||||
|
||||
```python
|
||||
| asc() -> OrderAction
|
||||
```
|
||||
|
||||
works as sql `column asc`
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(ormar.queryset.actions.OrderGroup)`: OrderGroup for operator
|
||||
|
||||
<a name="queryset.field_accessor.FieldAccessor.desc"></a>
|
||||
#### desc
|
||||
|
||||
```python
|
||||
| desc() -> OrderAction
|
||||
```
|
||||
|
||||
works as sql `column desc`
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(ormar.queryset.actions.OrderGroup)`: OrderGroup for operator
|
||||
|
||||
@ -27,7 +27,7 @@ Shortcut for ormar's model AliasManager stored on Meta.
|
||||
|
||||
```python
|
||||
| @property
|
||||
| to_table() -> str
|
||||
| to_table() -> sqlalchemy.Table
|
||||
```
|
||||
|
||||
Shortcut to table name of the next model
|
||||
@ -172,6 +172,36 @@ Updates the used aliases list directly.
|
||||
|
||||
Process order_by causes for non m2m relations.
|
||||
|
||||
<a name="queryset.join.SqlJoin._verify_allowed_order_field"></a>
|
||||
#### \_verify\_allowed\_order\_field
|
||||
|
||||
```python
|
||||
| _verify_allowed_order_field(order_by: str) -> None
|
||||
```
|
||||
|
||||
Verifies if proper field string is used.
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `order_by (str)`: string with order by definition
|
||||
|
||||
<a name="queryset.join.SqlJoin._get_alias_and_model"></a>
|
||||
#### \_get\_alias\_and\_model
|
||||
|
||||
```python
|
||||
| _get_alias_and_model(order_by: str) -> Tuple[str, Type["Model"]]
|
||||
```
|
||||
|
||||
Returns proper model and alias to be applied in the clause.
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `order_by (str)`: string with order by definition
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(Tuple[str, Type["Model"]])`: alias and model to be used in clause
|
||||
|
||||
<a name="queryset.join.SqlJoin._get_order_bys"></a>
|
||||
#### \_get\_order\_bys
|
||||
|
||||
|
||||
@ -241,7 +241,7 @@ Calls itself recurrently to extract deeper nested relations of related model.
|
||||
#### \_run\_prefetch\_query
|
||||
|
||||
```python
|
||||
| async _run_prefetch_query(target_field: Type["BaseField"], excludable: "ExcludableItems", filter_clauses: List, related_field_name: str) -> Tuple[str, str, List]
|
||||
| async _run_prefetch_query(target_field: "BaseField", excludable: "ExcludableItems", filter_clauses: List, related_field_name: str) -> Tuple[str, str, List]
|
||||
```
|
||||
|
||||
Actually runs the queries against the database and populates the raw response
|
||||
@ -252,7 +252,7 @@ models.
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `target_field (Type["BaseField"])`: ormar field with relation definition
|
||||
- `target_field ("BaseField")`: ormar field with relation definition
|
||||
- `filter_clauses (List[sqlalchemy.sql.elements.TextClause])`: list of clauses, actually one clause with ids of relation
|
||||
|
||||
**Returns**:
|
||||
@ -283,14 +283,14 @@ deeper on related model and already loaded in select related query.
|
||||
#### \_update\_already\_loaded\_rows
|
||||
|
||||
```python
|
||||
| _update_already_loaded_rows(target_field: Type["BaseField"], prefetch_dict: Dict, orders_by: Dict) -> None
|
||||
| _update_already_loaded_rows(target_field: "BaseField", prefetch_dict: Dict, orders_by: Dict) -> None
|
||||
```
|
||||
|
||||
Updates models that are already loaded, usually children of children.
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `target_field (Type["BaseField"])`: ormar field with relation definition
|
||||
- `target_field ("BaseField")`: ormar field with relation definition
|
||||
- `prefetch_dict (Dict)`: dictionaries of related models to prefetch
|
||||
- `orders_by (Dict)`: dictionary of order by clauses by model
|
||||
|
||||
@ -298,7 +298,7 @@ Updates models that are already loaded, usually children of children.
|
||||
#### \_populate\_rows
|
||||
|
||||
```python
|
||||
| _populate_rows(rows: List, target_field: Type["ForeignKeyField"], parent_model: Type["Model"], table_prefix: str, exclude_prefix: str, excludable: "ExcludableItems", prefetch_dict: Dict, orders_by: Dict) -> None
|
||||
| _populate_rows(rows: List, target_field: "ForeignKeyField", parent_model: Type["Model"], table_prefix: str, exclude_prefix: str, excludable: "ExcludableItems", prefetch_dict: Dict, orders_by: Dict) -> None
|
||||
```
|
||||
|
||||
Instantiates children models extracted from given relation.
|
||||
@ -314,7 +314,7 @@ and set on the parent model after sorting if needed.
|
||||
|
||||
- `excludable (ExcludableItems)`: structure of fields to include and exclude
|
||||
- `rows (List[sqlalchemy.engine.result.RowProxy])`: raw sql response from the prefetch query
|
||||
- `target_field (Type["BaseField"])`: field with relation definition from parent model
|
||||
- `target_field ("BaseField")`: field with relation definition from parent model
|
||||
- `parent_model (Type[Model])`: model with relation definition
|
||||
- `table_prefix (str)`: prefix of the target table from current relation
|
||||
- `prefetch_dict (Dict)`: dictionaries of related models to prefetch
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
## QuerySet Objects
|
||||
|
||||
```python
|
||||
class QuerySet()
|
||||
class QuerySet(Generic[T])
|
||||
```
|
||||
|
||||
Main class to perform database queries, exposed on each model as objects attribute.
|
||||
@ -29,7 +29,7 @@ Shortcut to model class Meta set on QuerySet model.
|
||||
|
||||
```python
|
||||
| @property
|
||||
| model() -> Type["Model"]
|
||||
| model() -> Type["T"]
|
||||
```
|
||||
|
||||
Shortcut to model class set on QuerySet.
|
||||
@ -52,7 +52,7 @@ all not passed params are taken from current values.
|
||||
#### \_prefetch\_related\_models
|
||||
|
||||
```python
|
||||
| async _prefetch_related_models(models: Sequence[Optional["Model"]], rows: List) -> Sequence[Optional["Model"]]
|
||||
| async _prefetch_related_models(models: List[Optional["T"]], rows: List) -> List[Optional["T"]]
|
||||
```
|
||||
|
||||
Performs prefetch query for selected models names.
|
||||
@ -70,7 +70,7 @@ Performs prefetch query for selected models names.
|
||||
#### \_process\_query\_result\_rows
|
||||
|
||||
```python
|
||||
| _process_query_result_rows(rows: List) -> Sequence[Optional["Model"]]
|
||||
| _process_query_result_rows(rows: List) -> List[Optional["T"]]
|
||||
```
|
||||
|
||||
Process database rows and initialize ormar Model from each of the rows.
|
||||
@ -83,12 +83,29 @@ Process database rows and initialize ormar Model from each of the rows.
|
||||
|
||||
`(List[Model])`: list of models
|
||||
|
||||
<a name="queryset.queryset.QuerySet._resolve_filter_groups"></a>
|
||||
#### \_resolve\_filter\_groups
|
||||
|
||||
```python
|
||||
| _resolve_filter_groups(groups: Any) -> Tuple[List[FilterGroup], List[str]]
|
||||
```
|
||||
|
||||
Resolves filter groups to populate FilterAction params in group tree.
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `groups (Any)`: tuple of FilterGroups
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(Tuple[List[FilterGroup], List[str]])`: list of resolver groups
|
||||
|
||||
<a name="queryset.queryset.QuerySet.check_single_result_rows_count"></a>
|
||||
#### check\_single\_result\_rows\_count
|
||||
|
||||
```python
|
||||
| @staticmethod
|
||||
| check_single_result_rows_count(rows: Sequence[Optional["Model"]]) -> None
|
||||
| check_single_result_rows_count(rows: Sequence[Optional["T"]]) -> None
|
||||
```
|
||||
|
||||
Verifies if the result has one and only one row.
|
||||
@ -149,7 +166,7 @@ If any of the params is not passed the QuerySet own value is used.
|
||||
#### filter
|
||||
|
||||
```python
|
||||
| filter(_exclude: bool = False, **kwargs: Any) -> "QuerySet"
|
||||
| filter(*args: Any, *, _exclude: bool = False, **kwargs: Any) -> "QuerySet[T]"
|
||||
```
|
||||
|
||||
Allows you to filter by any `Model` attribute/field
|
||||
@ -162,6 +179,8 @@ You can use special filter suffix to change the filter operands:
|
||||
* contains - like `album__name__contains='Mal'` (sql like)
|
||||
* icontains - like `album__name__icontains='mal'` (sql like case insensitive)
|
||||
* in - like `album__name__in=['Malibu', 'Barclay']` (sql in)
|
||||
* isnull - like `album__name__isnull=True` (sql is null)
|
||||
(isnotnull `album__name__isnull=False` (sql is not null))
|
||||
* gt - like `position__gt=3` (sql >)
|
||||
* gte - like `position__gte=3` (sql >=)
|
||||
* lt - like `position__lt=3` (sql <)
|
||||
@ -184,7 +203,7 @@ You can use special filter suffix to change the filter operands:
|
||||
#### exclude
|
||||
|
||||
```python
|
||||
| exclude(**kwargs: Any) -> "QuerySet"
|
||||
| exclude(*args: Any, **kwargs: Any) -> "QuerySet[T]"
|
||||
```
|
||||
|
||||
Works exactly the same as filter and all modifiers (suffixes) are the same,
|
||||
@ -211,7 +230,7 @@ becomes a union of conditions.
|
||||
#### select\_related
|
||||
|
||||
```python
|
||||
| select_related(related: Union[List, str]) -> "QuerySet"
|
||||
| select_related(related: Union[List, str]) -> "QuerySet[T]"
|
||||
```
|
||||
|
||||
Allows to prefetch related models during the same query.
|
||||
@ -232,11 +251,40 @@ To chain related `Models` relation use double underscores between names.
|
||||
|
||||
`(QuerySet)`: QuerySet
|
||||
|
||||
<a name="queryset.queryset.QuerySet.select_all"></a>
|
||||
#### select\_all
|
||||
|
||||
```python
|
||||
| select_all(follow: bool = False) -> "QuerySet[T]"
|
||||
```
|
||||
|
||||
By default adds only directly related models.
|
||||
|
||||
If follow=True is set it adds also related models of related models.
|
||||
|
||||
To not get stuck in an infinite loop as related models also keep a relation
|
||||
to parent model visited models set is kept.
|
||||
|
||||
That way already visited models that are nested are loaded, but the load do not
|
||||
follow them inside. So Model A -> Model B -> Model C -> Model A -> Model X
|
||||
will load second Model A but will never follow into Model X.
|
||||
Nested relations of those kind need to be loaded manually.
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `follow (bool)`: flag to trigger deep save -
|
||||
by default only directly related models are saved
|
||||
with follow=True also related models of related models are saved
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(Model)`: reloaded Model
|
||||
|
||||
<a name="queryset.queryset.QuerySet.prefetch_related"></a>
|
||||
#### prefetch\_related
|
||||
|
||||
```python
|
||||
| prefetch_related(related: Union[List, str]) -> "QuerySet"
|
||||
| prefetch_related(related: Union[List, str]) -> "QuerySet[T]"
|
||||
```
|
||||
|
||||
Allows to prefetch related models during query - but opposite to
|
||||
@ -262,7 +310,7 @@ To chain related `Models` relation use double underscores between names.
|
||||
#### fields
|
||||
|
||||
```python
|
||||
| fields(columns: Union[List, str, Set, Dict], _is_exclude: bool = False) -> "QuerySet"
|
||||
| fields(columns: Union[List, str, Set, Dict], _is_exclude: bool = False) -> "QuerySet[T]"
|
||||
```
|
||||
|
||||
With `fields()` you can select subset of model columns to limit the data load.
|
||||
@ -314,7 +362,7 @@ To include whole nested model specify model related field name and ellipsis.
|
||||
#### exclude\_fields
|
||||
|
||||
```python
|
||||
| exclude_fields(columns: Union[List, str, Set, Dict]) -> "QuerySet"
|
||||
| exclude_fields(columns: Union[List, str, Set, Dict]) -> "QuerySet[T]"
|
||||
```
|
||||
|
||||
With `exclude_fields()` you can select subset of model columns that will
|
||||
@ -349,7 +397,7 @@ if explicitly excluded.
|
||||
#### order\_by
|
||||
|
||||
```python
|
||||
| order_by(columns: Union[List, str]) -> "QuerySet"
|
||||
| order_by(columns: Union[List, str, OrderAction]) -> "QuerySet[T]"
|
||||
```
|
||||
|
||||
With `order_by()` you can order the results from database based on your
|
||||
@ -413,6 +461,62 @@ Returns number of rows matching the given criteria
|
||||
|
||||
`(int)`: number of rows
|
||||
|
||||
<a name="queryset.queryset.QuerySet.max"></a>
|
||||
#### max
|
||||
|
||||
```python
|
||||
| async max(columns: Union[str, List[str]]) -> Any
|
||||
```
|
||||
|
||||
Returns max value of columns for rows matching the given criteria
|
||||
(applied with `filter` and `exclude` if set before).
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(Any)`: max value of column(s)
|
||||
|
||||
<a name="queryset.queryset.QuerySet.min"></a>
|
||||
#### min
|
||||
|
||||
```python
|
||||
| async min(columns: Union[str, List[str]]) -> Any
|
||||
```
|
||||
|
||||
Returns min value of columns for rows matching the given criteria
|
||||
(applied with `filter` and `exclude` if set before).
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(Any)`: min value of column(s)
|
||||
|
||||
<a name="queryset.queryset.QuerySet.sum"></a>
|
||||
#### sum
|
||||
|
||||
```python
|
||||
| async sum(columns: Union[str, List[str]]) -> Any
|
||||
```
|
||||
|
||||
Returns sum value of columns for rows matching the given criteria
|
||||
(applied with `filter` and `exclude` if set before).
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(int)`: sum value of columns
|
||||
|
||||
<a name="queryset.queryset.QuerySet.avg"></a>
|
||||
#### avg
|
||||
|
||||
```python
|
||||
| async avg(columns: Union[str, List[str]]) -> Any
|
||||
```
|
||||
|
||||
Returns avg value of columns for rows matching the given criteria
|
||||
(applied with `filter` and `exclude` if set before).
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(Union[int, float, List])`: avg value of columns
|
||||
|
||||
<a name="queryset.queryset.QuerySet.update"></a>
|
||||
#### update
|
||||
|
||||
@ -438,7 +542,7 @@ each=True flag to affect whole table.
|
||||
#### delete
|
||||
|
||||
```python
|
||||
| async delete(each: bool = False, **kwargs: Any) -> int
|
||||
| async delete(*args: Any, *, each: bool = False, **kwargs: Any) -> int
|
||||
```
|
||||
|
||||
Deletes from the model table after applying the filters from kwargs.
|
||||
@ -459,7 +563,7 @@ each=True flag to affect whole table.
|
||||
#### paginate
|
||||
|
||||
```python
|
||||
| paginate(page: int, page_size: int = 20) -> "QuerySet"
|
||||
| paginate(page: int, page_size: int = 20) -> "QuerySet[T]"
|
||||
```
|
||||
|
||||
You can paginate the result which is a combination of offset and limit clauses.
|
||||
@ -478,7 +582,7 @@ Limit is set to page size and offset is set to (page-1) * page_size.
|
||||
#### limit
|
||||
|
||||
```python
|
||||
| limit(limit_count: int, limit_raw_sql: bool = None) -> "QuerySet"
|
||||
| limit(limit_count: int, limit_raw_sql: bool = None) -> "QuerySet[T]"
|
||||
```
|
||||
|
||||
You can limit the results to desired number of parent models.
|
||||
@ -499,7 +603,7 @@ models use the `limit_raw_sql` parameter flag, and set it to `True`.
|
||||
#### offset
|
||||
|
||||
```python
|
||||
| offset(offset: int, limit_raw_sql: bool = None) -> "QuerySet"
|
||||
| offset(offset: int, limit_raw_sql: bool = None) -> "QuerySet[T]"
|
||||
```
|
||||
|
||||
You can also offset the results by desired number of main models.
|
||||
@ -520,7 +624,7 @@ models use the `limit_raw_sql` parameter flag, and set it to `True`.
|
||||
#### first
|
||||
|
||||
```python
|
||||
| async first(**kwargs: Any) -> "Model"
|
||||
| async first(*args: Any, **kwargs: Any) -> "T"
|
||||
```
|
||||
|
||||
Gets the first row from the db ordered by primary key column ascending.
|
||||
@ -538,11 +642,34 @@ Gets the first row from the db ordered by primary key column ascending.
|
||||
|
||||
`(Model)`: returned model
|
||||
|
||||
<a name="queryset.queryset.QuerySet.get_or_none"></a>
|
||||
#### get\_or\_none
|
||||
|
||||
```python
|
||||
| async get_or_none(*args: Any, **kwargs: Any) -> Optional["T"]
|
||||
```
|
||||
|
||||
Get's the first row from the db meeting the criteria set by kwargs.
|
||||
|
||||
If no criteria set it will return the last row in db sorted by pk.
|
||||
|
||||
Passing a criteria is actually calling filter(**kwargs) method described below.
|
||||
|
||||
If not match is found None will be returned.
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `kwargs (Any)`: fields names and proper value types
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(Model)`: returned model
|
||||
|
||||
<a name="queryset.queryset.QuerySet.get"></a>
|
||||
#### get
|
||||
|
||||
```python
|
||||
| async get(**kwargs: Any) -> "Model"
|
||||
| async get(*args: Any, **kwargs: Any) -> "T"
|
||||
```
|
||||
|
||||
Get's the first row from the db meeting the criteria set by kwargs.
|
||||
@ -568,7 +695,7 @@ Passing a criteria is actually calling filter(**kwargs) method described below.
|
||||
#### get\_or\_create
|
||||
|
||||
```python
|
||||
| async get_or_create(**kwargs: Any) -> "Model"
|
||||
| async get_or_create(*args: Any, **kwargs: Any) -> "T"
|
||||
```
|
||||
|
||||
Combination of create and get methods.
|
||||
@ -589,7 +716,7 @@ it creates a new one with given kwargs.
|
||||
#### update\_or\_create
|
||||
|
||||
```python
|
||||
| async update_or_create(**kwargs: Any) -> "Model"
|
||||
| async update_or_create(**kwargs: Any) -> "T"
|
||||
```
|
||||
|
||||
Updates the model, or in case there is no match in database creates a new one.
|
||||
@ -606,7 +733,7 @@ Updates the model, or in case there is no match in database creates a new one.
|
||||
#### all
|
||||
|
||||
```python
|
||||
| async all(**kwargs: Any) -> Sequence[Optional["Model"]]
|
||||
| async all(*args: Any, **kwargs: Any) -> List[Optional["T"]]
|
||||
```
|
||||
|
||||
Returns all rows from a database for given model for set filter options.
|
||||
@ -627,7 +754,7 @@ If there are no rows meeting the criteria an empty list is returned.
|
||||
#### create
|
||||
|
||||
```python
|
||||
| async create(**kwargs: Any) -> "Model"
|
||||
| async create(**kwargs: Any) -> "T"
|
||||
```
|
||||
|
||||
Creates the model instance, saves it in a database and returns the updates model
|
||||
@ -647,7 +774,7 @@ The allowed kwargs are `Model` fields names and proper value types.
|
||||
#### bulk\_create
|
||||
|
||||
```python
|
||||
| async bulk_create(objects: List["Model"]) -> None
|
||||
| async bulk_create(objects: List["T"]) -> None
|
||||
```
|
||||
|
||||
Performs a bulk update in one database session to speed up the process.
|
||||
@ -666,7 +793,7 @@ Bulk operations do not send signals.
|
||||
#### bulk\_update
|
||||
|
||||
```python
|
||||
| async bulk_update(objects: List["Model"], columns: List[str] = None) -> None
|
||||
| async bulk_update(objects: List["T"], columns: List[str] = None) -> None
|
||||
```
|
||||
|
||||
Performs bulk update in one database session to speed up the process.
|
||||
|
||||
@ -28,6 +28,16 @@ Applies order_by queries on main model when it's used as a subquery.
|
||||
That way the subquery with limit and offset only on main model has proper
|
||||
sorting applied and correct models are fetched.
|
||||
|
||||
<a name="queryset.query.Query._apply_default_model_sorting"></a>
|
||||
#### \_apply\_default\_model\_sorting
|
||||
|
||||
```python
|
||||
| _apply_default_model_sorting() -> None
|
||||
```
|
||||
|
||||
Applies orders_by from model Meta class (if provided), if it was not provided
|
||||
it was filled by metaclass so it's always there and falls back to pk column
|
||||
|
||||
<a name="queryset.query.Query._pagination_query_required"></a>
|
||||
#### \_pagination\_query\_required
|
||||
|
||||
@ -62,11 +72,13 @@ Returns ready to run query with all joins and clauses.
|
||||
|
||||
`(sqlalchemy.sql.selectable.Select)`: ready to run query with all joins and clauses.
|
||||
|
||||
<a name="queryset.query.Query._build_pagination_subquery"></a>
|
||||
#### \_build\_pagination\_subquery
|
||||
<a name="queryset.query.Query._build_pagination_condition"></a>
|
||||
#### \_build\_pagination\_condition
|
||||
|
||||
```python
|
||||
| _build_pagination_subquery() -> sqlalchemy.sql.select
|
||||
| _build_pagination_condition() -> Tuple[
|
||||
| sqlalchemy.sql.expression.TextClause, sqlalchemy.sql.expression.TextClause
|
||||
| ]
|
||||
```
|
||||
|
||||
In order to apply limit and offset on main table in join only
|
||||
@ -78,9 +90,8 @@ Needed only if limit or offset are set, the flag limit_sql_raw is not set
|
||||
and query has select_related applied. Otherwise we can limit/offset normally
|
||||
at the end of whole query.
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(sqlalchemy.sql.select)`: constructed subquery on main table with limit, offset and order applied
|
||||
The condition is added to filters to filter out desired number of main model
|
||||
primary key values. Whole query is used to determine the values.
|
||||
|
||||
<a name="queryset.query.Query._apply_expression_modifiers"></a>
|
||||
#### \_apply\_expression\_modifiers
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
#### check\_node\_not\_dict\_or\_not\_last\_node
|
||||
|
||||
```python
|
||||
check_node_not_dict_or_not_last_node(part: str, parts: List, current_level: Any) -> bool
|
||||
check_node_not_dict_or_not_last_node(part: str, is_last: bool, current_level: Any) -> bool
|
||||
```
|
||||
|
||||
Checks if given name is not present in the current level of the structure.
|
||||
@ -86,6 +86,27 @@ only other values are overwritten.
|
||||
|
||||
`(Dict)`: combination of both dicts
|
||||
|
||||
<a name="queryset.utils.subtract_dict"></a>
|
||||
#### subtract\_dict
|
||||
|
||||
```python
|
||||
subtract_dict(current_dict: Any, updating_dict: Any) -> Dict
|
||||
```
|
||||
|
||||
Update one dict with another but with regard for nested keys.
|
||||
|
||||
That way nested sets are unionised, dicts updated and
|
||||
only other values are overwritten.
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `current_dict (Dict[str, ellipsis])`: dict to update
|
||||
- `updating_dict (Dict)`: dict with values to update
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(Dict)`: combination of both dicts
|
||||
|
||||
<a name="queryset.utils.update_dict_from_list"></a>
|
||||
#### update\_dict\_from\_list
|
||||
|
||||
@ -169,3 +190,24 @@ constructed, extracts alias based on last relation leading to target model.
|
||||
|
||||
`(Tuple[str, Type["Model"], str])`: table prefix, target model and relation string
|
||||
|
||||
<a name="queryset.utils._process_through_field"></a>
|
||||
#### \_process\_through\_field
|
||||
|
||||
```python
|
||||
_process_through_field(related_parts: List, relation: Optional[str], related_field: "BaseField", previous_model: Type["Model"], previous_models: List[Type["Model"]]) -> Tuple[Type["Model"], Optional[str], bool]
|
||||
```
|
||||
|
||||
Helper processing through models as they need to be treated differently.
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `related_parts (List[str])`: split relation string
|
||||
- `relation (str)`: relation name
|
||||
- `related_field ("ForeignKeyField")`: field with relation declaration
|
||||
- `previous_model (Type["Model"])`: model from which relation is coming
|
||||
- `previous_models (List[Type["Model"]])`: list of already visited models in relation chain
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(Tuple[Type["Model"], str, bool])`: previous_model, relation, is_through
|
||||
|
||||
|
||||
Reference in New Issue
Block a user