Correct spelling mistakes (#1163)
Co-authored-by: collerek <collerek@gmail.com>
This commit is contained in:
@ -420,7 +420,7 @@ async def filter_and_sort():
|
|||||||
|
|
||||||
async def subset_of_columns():
|
async def subset_of_columns():
|
||||||
# to exclude some columns from loading when querying the database
|
# to exclude some columns from loading when querying the database
|
||||||
# you can use fileds() method
|
# you can use fields() method
|
||||||
hobbit = await Book.objects.fields(["title"]).get(title="The Hobbit")
|
hobbit = await Book.objects.fields(["title"]).get(title="The Hobbit")
|
||||||
# note that fields not included in fields are empty (set to None)
|
# note that fields not included in fields are empty (set to None)
|
||||||
assert hobbit.year is None
|
assert hobbit.year is None
|
||||||
|
|||||||
@ -37,7 +37,7 @@ class User(ormar.Model):
|
|||||||
category: str = ormar.String(max_length=255, default="User")
|
category: str = ormar.String(max_length=255, default="User")
|
||||||
```
|
```
|
||||||
|
|
||||||
In above example fields `id` (is an `autoincrement` `Integer`), `first_name` ( has `nullable=True`) and `category` (has `default`) are optional and can be skipped in response and model wil still validate.
|
In above example fields `id` (is an `autoincrement` `Integer`), `first_name` ( has `nullable=True`) and `category` (has `default`) are optional and can be skipped in response and model will still validate.
|
||||||
|
|
||||||
If the field is nullable you don't have to include it in payload during creation as well as in response, so given example above you can:
|
If the field is nullable you don't have to include it in payload during creation as well as in response, so given example above you can:
|
||||||
|
|
||||||
@ -75,9 +75,9 @@ async def create_user3(user: RequestUser): # use the generated model here
|
|||||||
!!!Warning
|
!!!Warning
|
||||||
The `get_pydantic` method generates all models in a tree of nested models according to an algorithm that allows to avoid loops in models (same algorithm that is used in `dict()`, `select_all()` etc.)
|
The `get_pydantic` method generates all models in a tree of nested models according to an algorithm that allows to avoid loops in models (same algorithm that is used in `dict()`, `select_all()` etc.)
|
||||||
|
|
||||||
That means that nested models won't have reference to parent model (by default ormar relation is biderectional).
|
That means that nested models won't have reference to parent model (by default ormar relation is bidirectional).
|
||||||
|
|
||||||
Note also that if given model exists in a tree more than once it will be doubled in pydantic models (each occurance will have separate own model). That way you can exclude/include different fields on different leafs of the tree.
|
Note also that if given model exists in a tree more than once it will be doubled in pydantic models (each occurrence will have separate own model). That way you can exclude/include different fields on different leafs of the tree.
|
||||||
|
|
||||||
#### Mypy and type checking
|
#### Mypy and type checking
|
||||||
|
|
||||||
|
|||||||
@ -36,7 +36,7 @@ class User(ormar.Model):
|
|||||||
category: str = ormar.String(max_length=255, default="User")
|
category: str = ormar.String(max_length=255, default="User")
|
||||||
```
|
```
|
||||||
|
|
||||||
In above example fields `id` (is an `autoincrement` `Integer`), `first_name` ( has `nullable=True`) and `category` (has `default`) are optional and can be skipped in response and model wil still validate.
|
In above example fields `id` (is an `autoincrement` `Integer`), `first_name` ( has `nullable=True`) and `category` (has `default`) are optional and can be skipped in response and model will still validate.
|
||||||
|
|
||||||
If the field is nullable you don't have to include it in payload during creation as well as in response, so given example above you can:
|
If the field is nullable you don't have to include it in payload during creation as well as in response, so given example above you can:
|
||||||
|
|
||||||
@ -143,7 +143,7 @@ async def create_user(user: User):
|
|||||||
return await user.save()
|
return await user.save()
|
||||||
```
|
```
|
||||||
|
|
||||||
Note that you can go in deeper models with double underscore, and if you wan't to exclude multiple fields from nested model you need to prefix them with full path.
|
Note that you can go in deeper models with double underscore, and if you want to exclude multiple fields from nested model you need to prefix them with full path.
|
||||||
In example `response_model_exclude={"category__priority", "category__other_field", category__nested_model__nested_model_field}` etc.
|
In example `response_model_exclude={"category__priority", "category__other_field", category__nested_model__nested_model_field}` etc.
|
||||||
|
|
||||||
!!!Note
|
!!!Note
|
||||||
@ -215,9 +215,9 @@ async def create_user3(user: User):
|
|||||||
!!!Warning
|
!!!Warning
|
||||||
The `get_pydantic` method generates all models in a tree of nested models according to an algorithm that allows to avoid loops in models (same algorithm that is used in `dict()`, `select_all()` etc.)
|
The `get_pydantic` method generates all models in a tree of nested models according to an algorithm that allows to avoid loops in models (same algorithm that is used in `dict()`, `select_all()` etc.)
|
||||||
|
|
||||||
That means that nested models won't have reference to parent model (by default ormar relation is biderectional).
|
That means that nested models won't have reference to parent model (by default ormar relation is bidirectional).
|
||||||
|
|
||||||
Note also that if given model exists in a tree more than once it will be doubled in pydantic models (each occurance will have separate own model). That way you can exclude/include different fields on different leafs of the tree.
|
Note also that if given model exists in a tree more than once it will be doubled in pydantic models (each occurrence will have separate own model). That way you can exclude/include different fields on different leafs of the tree.
|
||||||
|
|
||||||
### Separate `pydantic` model
|
### Separate `pydantic` model
|
||||||
|
|
||||||
|
|||||||
@ -222,7 +222,7 @@ It will add both: validation in `pydantic` model and will display available opti
|
|||||||
therefore it will be available in docs of `fastapi`.
|
therefore it will be available in docs of `fastapi`.
|
||||||
|
|
||||||
If you still want to use `Enum` in your application you can do this by passing a `Enum` into choices
|
If you still want to use `Enum` in your application you can do this by passing a `Enum` into choices
|
||||||
and later pass value of given option to a given field (note tha Enum is not JsonSerializable).
|
and later pass value of given option to a given field (note that Enum is not JsonSerializable).
|
||||||
|
|
||||||
```python
|
```python
|
||||||
# note that imports and endpoints declaration
|
# note that imports and endpoints declaration
|
||||||
|
|||||||
@ -238,7 +238,7 @@ def test_excluding_property_field_in_endpoints2():
|
|||||||
"last_name",
|
"last_name",
|
||||||
"created_date",
|
"created_date",
|
||||||
]
|
]
|
||||||
# despite being decorated with property_field if you explictly exclude it it will be gone
|
# despite being decorated with property_field if you explicitly exclude it it will be gone
|
||||||
assert response.json().get("full_name") is None
|
assert response.json().get("full_name") is None
|
||||||
|
|
||||||
# <==related of code removed for clarity==>
|
# <==related of code removed for clarity==>
|
||||||
|
|||||||
@ -394,7 +394,7 @@ class Bus2(Car2):
|
|||||||
```
|
```
|
||||||
|
|
||||||
`Ormar` automatically modifies related_name of the fields to include the **table** name
|
`Ormar` automatically modifies related_name of the fields to include the **table** name
|
||||||
of the children models. The dafault name is original related_name + '_' + child table name.
|
of the children models. The default name is original related_name + '_' + child table name.
|
||||||
|
|
||||||
That way for class Truck2 the relation defined in
|
That way for class Truck2 the relation defined in
|
||||||
`owner: Person = ormar.ForeignKey(Person, related_name="owned")` becomes `owned_trucks2`
|
`owner: Person = ormar.ForeignKey(Person, related_name="owned")` becomes `owned_trucks2`
|
||||||
@ -509,13 +509,13 @@ class Category(DateFieldsModel, AuditModel):
|
|||||||
code: int = ormar.Integer()
|
code: int = ormar.Integer()
|
||||||
|
|
||||||
# Note that now the update fields in Category are gone in all places -> ormar fields, pydantic fields and sqlachemy table columns
|
# Note that now the update fields in Category are gone in all places -> ormar fields, pydantic fields and sqlachemy table columns
|
||||||
# so full list of available fileds in Category is: ["created_by", "created_date", "id", "name", "code"]
|
# so full list of available fields in Category is: ["created_by", "created_date", "id", "name", "code"]
|
||||||
```
|
```
|
||||||
|
|
||||||
Note how you simply need to provide field names and it will exclude the parent field regardless of from which parent model the field is coming from.
|
Note how you simply need to provide field names and it will exclude the parent field regardless of from which parent model the field is coming from.
|
||||||
|
|
||||||
!!!Note
|
!!!Note
|
||||||
Note that if you want to overwrite a field in child model you do not have to exclude it, simpy overwrite the field declaration in child model with same field name.
|
Note that if you want to overwrite a field in child model you do not have to exclude it, simply overwrite the field declaration in child model with same field name.
|
||||||
|
|
||||||
!!!Warning
|
!!!Warning
|
||||||
Note that this kind of behavior can confuse mypy and static type checkers, yet accessing the non existing fields will fail at runtime. That's why splitting the base classes is preferred.
|
Note that this kind of behavior can confuse mypy and static type checkers, yet accessing the non existing fields will fail at runtime. That's why splitting the base classes is preferred.
|
||||||
|
|||||||
@ -29,7 +29,7 @@ The benefit of using construct is the speed of execution due to skipped validati
|
|||||||
|
|
||||||
!!!warning
|
!!!warning
|
||||||
Bear in mind that due to skipped validation the `construct` method does not perform any conversions, checks etc.
|
Bear in mind that due to skipped validation the `construct` method does not perform any conversions, checks etc.
|
||||||
So it's your responsibility to provide tha data that is valid and can be consumed by the database.
|
So it's your responsibility to provide that data that is valid and can be consumed by the database.
|
||||||
|
|
||||||
The only two things that construct still performs are:
|
The only two things that construct still performs are:
|
||||||
|
|
||||||
@ -45,7 +45,7 @@ therefore it's listed here for clarity.
|
|||||||
|
|
||||||
Explanation of dict parameters:
|
Explanation of dict parameters:
|
||||||
|
|
||||||
### include (`ormar` modifed)
|
### include (`ormar` modified)
|
||||||
|
|
||||||
`include: Union[Set, Dict] = None`
|
`include: Union[Set, Dict] = None`
|
||||||
|
|
||||||
@ -630,7 +630,7 @@ to_save = {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
# initializa whole tree
|
# initialize whole tree
|
||||||
department = Department(**to_save)
|
department = Department(**to_save)
|
||||||
|
|
||||||
# save all at once (one after another)
|
# save all at once (one after another)
|
||||||
|
|||||||
@ -93,7 +93,7 @@ assert album == album2
|
|||||||
!!!warning
|
!!!warning
|
||||||
Despite being a equivalent row from database the `album` and `album2` in
|
Despite being a equivalent row from database the `album` and `album2` in
|
||||||
example above are 2 different python objects!
|
example above are 2 different python objects!
|
||||||
Updating one of them will not refresh the second one until you excplicitly load() the
|
Updating one of them will not refresh the second one until you explicitly load() the
|
||||||
fresh data from db.
|
fresh data from db.
|
||||||
|
|
||||||
!!!note
|
!!!note
|
||||||
|
|||||||
@ -583,7 +583,7 @@ books = (
|
|||||||
|
|
||||||
`get(*args, **kwargs) -> Model`
|
`get(*args, **kwargs) -> Model`
|
||||||
|
|
||||||
Get's the first row from the db meeting the criteria set by kwargs.
|
Gets the first row from the db meeting the criteria set by kwargs.
|
||||||
|
|
||||||
When any args and/or kwargs are passed it's a shortcut equivalent to calling `filter(*args, **kwargs).get()`
|
When any args and/or kwargs are passed it's a shortcut equivalent to calling `filter(*args, **kwargs).get()`
|
||||||
|
|
||||||
@ -713,7 +713,7 @@ Ordering in sql will be applied in order of names you provide in order_by.
|
|||||||
will result in 2 rows of result:
|
will result in 2 rows of result:
|
||||||
```
|
```
|
||||||
MODEL: 1 - Child Models: [3, 1] # encountered first in result, all children rows combined
|
MODEL: 1 - Child Models: [3, 1] # encountered first in result, all children rows combined
|
||||||
MODEL: 2 - Child Modles: [2]
|
MODEL: 2 - Child Models: [2]
|
||||||
```
|
```
|
||||||
|
|
||||||
The main model will never duplicate in the result
|
The main model will never duplicate in the result
|
||||||
|
|||||||
@ -33,7 +33,7 @@ To chain related `Models` relation use double underscores between names.
|
|||||||
!!!note
|
!!!note
|
||||||
If you are coming from `django` note that `ormar` `select_related` differs ->
|
If you are coming from `django` note that `ormar` `select_related` differs ->
|
||||||
in `django` you can `select_related`
|
in `django` you can `select_related`
|
||||||
only singe relation types, while in `ormar` you can select related across `ForeignKey`
|
only single relation types, while in `ormar` you can select related across `ForeignKey`
|
||||||
relation, reverse side of `ForeignKey` (so virtual auto generated keys) and `ManyToMany`
|
relation, reverse side of `ForeignKey` (so virtual auto generated keys) and `ManyToMany`
|
||||||
fields (so all relations as of current version).
|
fields (so all relations as of current version).
|
||||||
|
|
||||||
|
|||||||
@ -115,7 +115,7 @@ tracks = await Track.objects.offset(1).limit(1).all()
|
|||||||
|
|
||||||
`get(**kwargs) -> Model`
|
`get(**kwargs) -> Model`
|
||||||
|
|
||||||
Get's the first row from the db meeting the criteria set by kwargs.
|
Gets the first row from the db meeting the criteria set by kwargs.
|
||||||
|
|
||||||
If no criteria is set it will return the last row in db sorted by pk.
|
If no criteria is set it will return the last row in db sorted by pk.
|
||||||
(The criteria cannot be set also with filter/exclude).
|
(The criteria cannot be set also with filter/exclude).
|
||||||
|
|||||||
@ -23,7 +23,7 @@ Following methods allow you to load data from the database.
|
|||||||
|
|
||||||
`get(*args, **kwargs) -> Model`
|
`get(*args, **kwargs) -> Model`
|
||||||
|
|
||||||
Get's the first row from the db meeting the criteria set by kwargs.
|
Gets 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 column.
|
If no criteria set it will return the last row in db sorted by pk column.
|
||||||
|
|
||||||
@ -99,7 +99,7 @@ assert album == album2
|
|||||||
!!!warning
|
!!!warning
|
||||||
Despite being an equivalent row from database the `album` and `album2` in
|
Despite being an equivalent row from database the `album` and `album2` in
|
||||||
example above are 2 different python objects!
|
example above are 2 different python objects!
|
||||||
Updating one of them will not refresh the second one until you excplicitly load() the
|
Updating one of them will not refresh the second one until you explicitly load() the
|
||||||
fresh data from db.
|
fresh data from db.
|
||||||
|
|
||||||
!!!note
|
!!!note
|
||||||
|
|||||||
@ -100,7 +100,7 @@ for those models in fields
|
|||||||
```python hl_lines="1"
|
```python hl_lines="1"
|
||||||
all_cars = await Car.objects.select_related('manufacturer').fields('id').fields(
|
all_cars = await Car.objects.select_related('manufacturer').fields('id').fields(
|
||||||
['name']).all()
|
['name']).all()
|
||||||
# all fiels from company model are selected
|
# all fields from company model are selected
|
||||||
assert all_cars[0].manufacturer.name == 'Toyota'
|
assert all_cars[0].manufacturer.name == 'Toyota'
|
||||||
assert all_cars[0].manufacturer.founded == 1937
|
assert all_cars[0].manufacturer.founded == 1937
|
||||||
```
|
```
|
||||||
@ -263,7 +263,7 @@ for car in all_cars:
|
|||||||
# models selected in select_related but with no columns in fields list implies all fields
|
# models selected in select_related but with no columns in fields list implies all fields
|
||||||
all_cars = await Car.objects.select_related('manufacturer').exclude_fields('year').exclude_fields(
|
all_cars = await Car.objects.select_related('manufacturer').exclude_fields('year').exclude_fields(
|
||||||
['gear', 'gearbox_type']).all()
|
['gear', 'gearbox_type']).all()
|
||||||
# all fiels from company model are selected
|
# all fields from company model are selected
|
||||||
assert all_cars[0].manufacturer.name == 'Toyota'
|
assert all_cars[0].manufacturer.name == 'Toyota'
|
||||||
assert all_cars[0].manufacturer.founded == 1937
|
assert all_cars[0].manufacturer.founded == 1937
|
||||||
|
|
||||||
|
|||||||
@ -198,7 +198,7 @@ To customize the names of fields/relation in Through model now you can use new p
|
|||||||
Example:
|
Example:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
... # course declaration ommited
|
... # course declaration omitted
|
||||||
class Student(ormar.Model):
|
class Student(ormar.Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
database = database
|
database = database
|
||||||
|
|||||||
@ -511,7 +511,7 @@ In 0.10.9 ormar excludes versions with vulnerability in pinned dependencies.
|
|||||||
* By default `Through` model relation names default to related model name in lowercase.
|
* By default `Through` model relation names default to related model name in lowercase.
|
||||||
So in example like this:
|
So in example like this:
|
||||||
```python
|
```python
|
||||||
... # course declaration ommited
|
... # course declaration omitted
|
||||||
class Student(ormar.Model):
|
class Student(ormar.Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
database = database
|
database = database
|
||||||
@ -538,7 +538,7 @@ In 0.10.9 ormar excludes versions with vulnerability in pinned dependencies.
|
|||||||
|
|
||||||
Example:
|
Example:
|
||||||
```python
|
```python
|
||||||
... # course declaration ommited
|
... # course declaration omitted
|
||||||
class Student(ormar.Model):
|
class Student(ormar.Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
database = database
|
database = database
|
||||||
@ -672,7 +672,7 @@ In 0.10.9 ormar excludes versions with vulnerability in pinned dependencies.
|
|||||||
* Add 4 new signals -> `pre_relation_add`, `post_relation_add`, `pre_relation_remove` and `post_relation_remove`
|
* Add 4 new signals -> `pre_relation_add`, `post_relation_add`, `pre_relation_remove` and `post_relation_remove`
|
||||||
* The newly added signals are emitted for `ManyToMany` relations (both sides)
|
* The newly added signals are emitted for `ManyToMany` relations (both sides)
|
||||||
and reverse side of `ForeignKey` relation (same as `QuerysetProxy` is exposed).
|
and reverse side of `ForeignKey` relation (same as `QuerysetProxy` is exposed).
|
||||||
* Signals recieve following args: `sender: Type[Model]` - sender class,
|
* Signals receive following args: `sender: Type[Model]` - sender class,
|
||||||
`instance: Model` - instance to which related model is added, `child: Model` - model being added,
|
`instance: Model` - instance to which related model is added, `child: Model` - model being added,
|
||||||
`relation_name: str` - name of the relation to which child is added,
|
`relation_name: str` - name of the relation to which child is added,
|
||||||
for add signals also `passed_kwargs: Dict` - dict of kwargs passed to `add()`
|
for add signals also `passed_kwargs: Dict` - dict of kwargs passed to `add()`
|
||||||
@ -834,7 +834,7 @@ that most of the `ormar` functions are working your database **CREATED with orma
|
|||||||
* **Breaking:** During model construction if `Meta` class of the `Model` does not
|
* **Breaking:** During model construction if `Meta` class of the `Model` does not
|
||||||
include `metadata` or `database` now `ModelDefinitionError` will be raised instead of generic `AttributeError`.
|
include `metadata` or `database` now `ModelDefinitionError` will be raised instead of generic `AttributeError`.
|
||||||
* **Breaking:** `encode/databases` used for running the queries does not have a connection pool
|
* **Breaking:** `encode/databases` used for running the queries does not have a connection pool
|
||||||
for sqlite backend, meaning that each querry is run with a new connection and there is no way to
|
for sqlite backend, meaning that each query is run with a new connection and there is no way to
|
||||||
enable enforcing ForeignKeys constraints as those are by default turned off on every connection.
|
enable enforcing ForeignKeys constraints as those are by default turned off on every connection.
|
||||||
This is changed in `ormar` since >=0.9.0 and by default each sqlite3 query has `"PRAGMA foreign_keys=1;"`
|
This is changed in `ormar` since >=0.9.0 and by default each sqlite3 query has `"PRAGMA foreign_keys=1;"`
|
||||||
run so now each sqlite3 connection by default enforces ForeignKey constraints including cascades.
|
run so now each sqlite3 connection by default enforces ForeignKey constraints including cascades.
|
||||||
@ -998,7 +998,7 @@ so now you can use those methods directly from relation
|
|||||||
* Model is saved after adding/removing `ManyToMany` related objects (through model instance auto saved/deleted)
|
* Model is saved after adding/removing `ManyToMany` related objects (through model instance auto saved/deleted)
|
||||||
* Model is **not** saved after change of any own field (including pk as `Model.pk` alias)
|
* Model is **not** saved after change of any own field (including pk as `Model.pk` alias)
|
||||||
* Model is **not** saved after adding/removing `ForeignKey` related object (fk column not saved)
|
* Model is **not** saved after adding/removing `ForeignKey` related object (fk column not saved)
|
||||||
* Model is **not** saved after instantation with `__init__` (w/o `QuerySet.create` or before calling `save`)
|
* Model is **not** saved after instantiation with `__init__` (w/o `QuerySet.create` or before calling `save`)
|
||||||
* Added `Model.upsert(**kwargs)` that performs `save()` if pk not set otherwise `update(**kwargs)`
|
* Added `Model.upsert(**kwargs)` that performs `save()` if pk not set otherwise `update(**kwargs)`
|
||||||
* Added `Model.save_related(follow=False)` that iterates all related objects in all relations and checks if they are saved. If not it calls `upsert()` on each of them.
|
* Added `Model.save_related(follow=False)` that iterates all related objects in all relations and checks if they are saved. If not it calls `upsert()` on each of them.
|
||||||
* **Breaking:** added raising exceptions if `add`-ing/`remove`-ing not saved (pk is None) models to `ManyToMany` relation
|
* **Breaking:** added raising exceptions if `add`-ing/`remove`-ing not saved (pk is None) models to `ManyToMany` relation
|
||||||
|
|||||||
@ -8,7 +8,7 @@ To use transactions use `database.transaction` as async context manager:
|
|||||||
|
|
||||||
```python
|
```python
|
||||||
async with database.transaction():
|
async with database.transaction():
|
||||||
# everyting called here will be one transaction
|
# everything called here will be one transaction
|
||||||
await Model1().save()
|
await Model1().save()
|
||||||
await Model2().save()
|
await Model2().save()
|
||||||
...
|
...
|
||||||
|
|||||||
@ -59,7 +59,7 @@ for car in all_cars:
|
|||||||
# models selected in select_related but with no columns in fields list implies all fields
|
# models selected in select_related but with no columns in fields list implies all fields
|
||||||
all_cars = await Car.objects.select_related('manufacturer').exclude_fields('year').exclude_fields(
|
all_cars = await Car.objects.select_related('manufacturer').exclude_fields('year').exclude_fields(
|
||||||
['gear', 'gearbox_type']).all()
|
['gear', 'gearbox_type']).all()
|
||||||
# all fiels from company model are selected
|
# all fields from company model are selected
|
||||||
assert all_cars[0].manufacturer.name == 'Toyota'
|
assert all_cars[0].manufacturer.name == 'Toyota'
|
||||||
assert all_cars[0].manufacturer.founded == 1937
|
assert all_cars[0].manufacturer.founded == 1937
|
||||||
|
|
||||||
|
|||||||
@ -254,7 +254,7 @@ async def filter_and_sort():
|
|||||||
|
|
||||||
async def subset_of_columns():
|
async def subset_of_columns():
|
||||||
# to exclude some columns from loading when querying the database
|
# to exclude some columns from loading when querying the database
|
||||||
# you can use fileds() method
|
# you can use fields() method
|
||||||
hobbit = await Book.objects.fields(["title"]).get(title="The Hobbit")
|
hobbit = await Book.objects.fields(["title"]).get(title="The Hobbit")
|
||||||
# note that fields not included in fields are empty (set to None)
|
# note that fields not included in fields are empty (set to None)
|
||||||
assert hobbit.year is None
|
assert hobbit.year is None
|
||||||
|
|||||||
@ -28,7 +28,7 @@ class PrefetchQueryMixin(RelationMixin):
|
|||||||
|
|
||||||
:param parent_model: related model that the relation lead to
|
:param parent_model: related model that the relation lead to
|
||||||
:type parent_model: Type[Model]
|
:type parent_model: Type[Model]
|
||||||
:param target_model: model on which query should be perfomed
|
:param target_model: model on which query should be performed
|
||||||
:type target_model: Type[Model]
|
:type target_model: Type[Model]
|
||||||
:param reverse: flag if the relation is reverse
|
:param reverse: flag if the relation is reverse
|
||||||
:type reverse: bool
|
:type reverse: bool
|
||||||
|
|||||||
@ -64,7 +64,7 @@ class NewBaseModel(pydantic.BaseModel, ModelTableProxy, metaclass=ModelMetaclass
|
|||||||
Constructed with ModelMetaclass which in turn also inherits pydantic metaclass.
|
Constructed with ModelMetaclass which in turn also inherits pydantic metaclass.
|
||||||
|
|
||||||
Abstracts away all internals and helper functions, so final Model class has only
|
Abstracts away all internals and helper functions, so final Model class has only
|
||||||
the logic concerned with database connection and data persistance.
|
the logic concerned with database connection and data persistence.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__slots__ = (
|
__slots__ = (
|
||||||
|
|||||||
@ -223,7 +223,7 @@ class Query:
|
|||||||
|
|
||||||
:param expr: select expression before clauses
|
:param expr: select expression before clauses
|
||||||
:type expr: sqlalchemy.sql.selectable.Select
|
:type expr: sqlalchemy.sql.selectable.Select
|
||||||
:return: expresion with all present clauses applied
|
:return: expression with all present clauses applied
|
||||||
:rtype: sqlalchemy.sql.selectable.Select
|
:rtype: sqlalchemy.sql.selectable.Select
|
||||||
"""
|
"""
|
||||||
expr = FilterQuery(filter_clauses=self.filter_clauses).apply(expr)
|
expr = FilterQuery(filter_clauses=self.filter_clauses).apply(expr)
|
||||||
|
|||||||
@ -926,7 +926,7 @@ class QuerySet(Generic[T]):
|
|||||||
|
|
||||||
async def get_or_none(self, *args: Any, **kwargs: Any) -> Optional["T"]:
|
async def get_or_none(self, *args: Any, **kwargs: Any) -> Optional["T"]:
|
||||||
"""
|
"""
|
||||||
Get's the first row from the db meeting the criteria set by kwargs.
|
Gets 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.
|
If no criteria set it will return the last row in db sorted by pk.
|
||||||
|
|
||||||
@ -947,7 +947,7 @@ class QuerySet(Generic[T]):
|
|||||||
|
|
||||||
async def get(self, *args: Any, **kwargs: Any) -> "T": # noqa: CCR001
|
async def get(self, *args: Any, **kwargs: Any) -> "T": # noqa: CCR001
|
||||||
"""
|
"""
|
||||||
Get's the first row from the db meeting the criteria set by kwargs.
|
Gets 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.
|
If no criteria set it will return the last row in db sorted by pk.
|
||||||
|
|
||||||
|
|||||||
@ -361,7 +361,7 @@ class QuerysetProxy(Generic[T]):
|
|||||||
|
|
||||||
async def get_or_none(self, *args: Any, **kwargs: Any) -> Optional["T"]:
|
async def get_or_none(self, *args: Any, **kwargs: Any) -> Optional["T"]:
|
||||||
"""
|
"""
|
||||||
Get's the first row from the db meeting the criteria set by kwargs.
|
Gets 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.
|
If no criteria set it will return the last row in db sorted by pk.
|
||||||
|
|
||||||
@ -386,7 +386,7 @@ class QuerysetProxy(Generic[T]):
|
|||||||
|
|
||||||
async def get(self, *args: Any, **kwargs: Any) -> "T":
|
async def get(self, *args: Any, **kwargs: Any) -> "T":
|
||||||
"""
|
"""
|
||||||
Get's the first row from the db meeting the criteria set by kwargs.
|
Gets 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.
|
If no criteria set it will return the last row in db sorted by pk.
|
||||||
|
|
||||||
@ -523,7 +523,7 @@ class QuerysetProxy(Generic[T]):
|
|||||||
"""
|
"""
|
||||||
Combination of create and get methods.
|
Combination of create and get methods.
|
||||||
|
|
||||||
Tries to get a row meeting the criteria fro kwargs
|
Tries to get a row meeting the criteria for kwargs
|
||||||
and if `NoMatch` exception is raised
|
and if `NoMatch` exception is raised
|
||||||
it creates a new one with given kwargs and _defaults.
|
it creates a new one with given kwargs and _defaults.
|
||||||
|
|
||||||
|
|||||||
@ -101,7 +101,7 @@ types-pkg-resources = "^0.1.3"
|
|||||||
types-requests = "^2.31.0"
|
types-requests = "^2.31.0"
|
||||||
types-toml = "^0.10.8"
|
types-toml = "^0.10.8"
|
||||||
|
|
||||||
# Documantation
|
# Documentation
|
||||||
mkdocs = "^1.5.2"
|
mkdocs = "^1.5.2"
|
||||||
mkdocs-material = ">=8.1.2,<9.2"
|
mkdocs-material = ">=8.1.2,<9.2"
|
||||||
mkdocs-material-extensions = "^1.1"
|
mkdocs-material-extensions = "^1.1"
|
||||||
|
|||||||
Reference in New Issue
Block a user