Skip to content

Commit

Permalink
fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
collerek committed Mar 10, 2024
2 parents 1bbf908 + 3a206dd commit 7517774
Show file tree
Hide file tree
Showing 30 changed files with 780 additions and 475 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/auto-merge-dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
steps:
- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v1.5.1
uses: dependabot/fetch-metadata@v1.6.0
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"

Expand Down
14 changes: 11 additions & 3 deletions .github/workflows/deploy-docs.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
name: Build Documentation using MkDocs
on:
push:
branches: [ master ]
# Pattern matched against refs/tags
tags:
- '**'
jobs:
build:
name: Build and Deploy Documentation
Expand All @@ -19,6 +21,12 @@ jobs:
poetry install --extras "all"
env:
POETRY_VIRTUALENVS_CREATE: false
- name: Deploy
- name: Set env
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- name: Test
run: |
mkdocs gh-deploy --force
echo $RELEASE_VERSION
echo ${{ env.RELEASE_VERSION }}
# - name: Deploy
# run: |
# mike deploy --push --update-aliases ${{ env.RELEASE_VERSION }} latest
4 changes: 2 additions & 2 deletions .github/workflows/test-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ jobs:
run: bash scripts/test.sh

- name: Upload coverage
uses: codecov/[email protected].4
uses: codecov/[email protected].6

- name: Test & publish code coverage
uses: paambaati/codeclimate-action@v4.0.0
uses: paambaati/codeclimate-action@v5.0.0
if: github.event.pull_request.head.repo.full_name == 'collerek/ormar'
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_COVERAGE_TOKEN }}
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ As part of the fastapi ecosystem `ormar` is supported in libraries that somehow

As of now `ormar` is supported by:

* [`fastapi-users`](https://github.com/frankie567/fastapi-users)
* [`fastapi-crudrouter`](https://github.com/awtkns/fastapi-crudrouter)
* [`fastapi-pagination`](https://github.com/uriyyo/fastapi-pagination)

Expand Down Expand Up @@ -420,7 +419,7 @@ async def filter_and_sort():

async def subset_of_columns():
# 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")
# note that fields not included in fields are empty (set to None)
assert hobbit.year is None
Expand Down
8 changes: 4 additions & 4 deletions docs/fastapi/requests.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class User(ormar.Model):
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:

Expand Down Expand Up @@ -75,9 +75,9 @@ async def create_user3(user: RequestUser): # use the generated model here
!!!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 `model_dump()`, `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

Expand Down Expand Up @@ -139,4 +139,4 @@ async def create_user3(user: UserCreate): # use pydantic model here
# note how now request param is a pydantic model and not the ormar one
# so you need to parse/convert it to ormar before you can use database
return await User(**user.model_dump()).save()
```
```
10 changes: 5 additions & 5 deletions docs/fastapi/response.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class User(ormar.Model):
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:

Expand Down Expand Up @@ -143,7 +143,7 @@ async def create_user(user: User):
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.

!!!Note
Expand Down Expand Up @@ -215,9 +215,9 @@ async def create_user3(user: User):
!!!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 `model_dump()`, `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

Expand All @@ -239,4 +239,4 @@ class UserBase(pydantic.BaseModel):
@app.post("/users3/", response_model=UserBase) # use pydantic model here
async def create_user3(user: User): #use ormar model here (but of course you CAN use pydantic also here)
return await user.save()
```
```
2 changes: 1 addition & 1 deletion docs/fields/field-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

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
# note that imports and endpoints declaration
Expand Down
6 changes: 3 additions & 3 deletions docs/models/inheritance.md
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ class Bus2(Car2):
```

`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
`owner: Person = ormar.ForeignKey(Person, related_name="owned")` becomes `owned_trucks2`
Expand Down Expand Up @@ -509,13 +509,13 @@ class Category(DateFieldsModel, AuditModel):
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
# 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
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
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.
Expand Down
6 changes: 3 additions & 3 deletions docs/models/methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ The benefit of using construct is the speed of execution due to skipped validati

!!!warning
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:

Expand All @@ -45,7 +45,7 @@ therefore it's listed here for clarity.

Explanation of dict parameters:

### include (`ormar` modifed)
### include (`ormar` modified)

`include: Union[Set, Dict] = None`

Expand Down Expand Up @@ -630,7 +630,7 @@ to_save = {
},
],
}
# initializa whole tree
# initialize whole tree
department = Department(**to_save)

# save all at once (one after another)
Expand Down
2 changes: 1 addition & 1 deletion docs/queries/create.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ assert album == album2
!!!warning
Despite being a equivalent row from database the `album` and `album2` in
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.

!!!note
Expand Down
4 changes: 2 additions & 2 deletions docs/queries/filter-and-sort.md
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ books = (

`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()`

Expand Down Expand Up @@ -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:
```
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
Expand Down
2 changes: 1 addition & 1 deletion docs/queries/joins-and-subqueries.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ To chain related `Models` relation use double underscores between names.
!!!note
If you are coming from `django` note that `ormar` `select_related` differs ->
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`
fields (so all relations as of current version).

Expand Down
4 changes: 2 additions & 2 deletions docs/queries/pagination-and-rows-number.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ tracks = await Track.objects.offset(1).limit(1).all()

`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.
(The criteria cannot be set also with filter/exclude).
Expand Down Expand Up @@ -166,4 +166,4 @@ objects from other side of the relation.
!!!tip
To read more about `QuerysetProxy` visit [querysetproxy][querysetproxy] section

[querysetproxy]: ../relations/queryset-proxy.md
[querysetproxy]: ../relations/queryset-proxy.md
4 changes: 2 additions & 2 deletions docs/queries/read.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Following methods allow you to load data from the database.

`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.

Expand Down Expand Up @@ -99,7 +99,7 @@ assert album == album2
!!!warning
Despite being an equivalent row from database the `album` and `album2` in
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.

!!!note
Expand Down
4 changes: 2 additions & 2 deletions docs/queries/select-columns.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ for those models in fields
```python hl_lines="1"
all_cars = await Car.objects.select_related('manufacturer').fields('id').fields(
['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.founded == 1937
```
Expand Down Expand Up @@ -263,7 +263,7 @@ for car in all_cars:
# 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(
['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.founded == 1937

Expand Down
4 changes: 2 additions & 2 deletions docs/relations/many-to-many.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ To customize the names of fields/relation in Through model now you can use new p
Example:

```python
... # course declaration ommited
... # course declaration omitted
class Student(ormar.Model):
class Meta:
database = database
Expand Down Expand Up @@ -419,4 +419,4 @@ To read which methods of QuerySet are available read below [querysetproxy][query
[exists]: ./queries.md#exists
[fields]: ./queries.md#fields
[exclude_fields]: ./queries.md#exclude_fields
[order_by]: ./queries.md#order_by
[order_by]: ./queries.md#order_by
10 changes: 5 additions & 5 deletions docs/releases.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
So in example like this:
```python
... # course declaration ommited
... # course declaration omitted
class Student(ormar.Model):
class Meta:
database = database
Expand All @@ -538,7 +538,7 @@ In 0.10.9 ormar excludes versions with vulnerability in pinned dependencies.

Example:
```python
... # course declaration ommited
... # course declaration omitted
class Student(ormar.Model):
class Meta:
database = database
Expand Down Expand Up @@ -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`
* The newly added signals are emitted for `ManyToMany` relations (both sides)
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,
`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()`
Expand Down Expand Up @@ -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
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
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.
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.
Expand Down Expand Up @@ -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 **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 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.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
Expand Down
4 changes: 2 additions & 2 deletions docs/transactions.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ To use transactions use `database.transaction` as async context manager:

```python
async with database.transaction():
# everyting called here will be one transaction
# everything called here will be one transaction
await Model1().save()
await Model2().save()
...
Expand Down Expand Up @@ -85,4 +85,4 @@ async def sample_test():
async with database.transaction(force_rollback=True):
# your test code here
...
```
```
2 changes: 1 addition & 1 deletion examples/script_from_readme.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ async def filter_and_sort():

async def subset_of_columns():
# 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")
# note that fields not included in fields are empty (set to None)
assert hobbit.year is None
Expand Down
7 changes: 7 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
site_name: ormar
site_url: 'https://collerek.github.io/ormar/'
site_description: A simple async ORM with fastapi in mind and pydantic validation.
nav:
- Overview: index.md
Expand Down Expand Up @@ -78,6 +79,10 @@ markdown_extensions:
- pymdownx.highlight:
linenums: true
plugins:
- mike:
alias_type: symlink
canonical_version: latest
version_selector: true
- search
- gen-files:
scripts:
Expand All @@ -98,6 +103,8 @@ extra:
analytics:
provider: google
property: UA-72514911-3
version:
provider: mike
extra_javascript:
- https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/highlight.min.js
- javascripts/config.js
Expand Down
2 changes: 1 addition & 1 deletion ormar/models/mixins/prefetch_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def get_clause_target_and_filter_column_name(
:param parent_model: related model that the relation lead to
: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]
:param reverse: flag if the relation is reverse
:type reverse: bool
Expand Down
Loading

0 comments on commit 7517774

Please sign in to comment.