Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
source = ormar, tests
omit = ./tests/test.db, *py.typed*
data_file = .coverage
concurrency = greenlet

[report]
omit = ./tests/test.db, *py.typed*
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ lint:
poetry run python -m ruff check . --fix

fmt:
poetry run python -m black .
poetry run python -m ruff format .

pre-commit: fmt lint type_check
3 changes: 2 additions & 1 deletion benchmarks/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
import time

import nest_asyncio
import ormar
import pytest
import pytest_asyncio
from tests.lifespan import init_tests
from tests.settings import create_config

import ormar

base_ormar_config = create_config()
nest_asyncio.apply()
pytestmark = pytest.mark.asyncio
Expand Down
5 changes: 3 additions & 2 deletions docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ git checkout -b my-new-feature-branch
# make your changes...

# 4. Formatting and linting
# ormar uses black for formatting, flake8 for linting and mypy for type hints check
# ormar uses ruff for formatting and linting and mypy for type hints check
# run all of the following as all those calls will be run on travis after every push
black ormar tests
ruff format ormar tests
ruff check ormar tests
flake8 ormar
mypy ormar tests

Expand Down
32 changes: 16 additions & 16 deletions docs/models/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ They are being managed in the background and you do not have to create them on y

To build an ormar model you simply need to inherit a `ormar.Model` class.

```Python hl_lines="9"
```Python hl_lines="10"
--8<-- "../docs_src/models/docs001.py"
```

Expand All @@ -23,7 +23,7 @@ Each table **has to** have a primary key column, which you specify by setting `p

Only one primary key column is allowed.

```Python hl_lines="15-17"
```Python hl_lines="16-18"
--8<-- "../docs_src/models/docs001.py"
```

Expand Down Expand Up @@ -60,7 +60,7 @@ you should get back exactly same value in `response`.).
!!!warning
pydantic fields have to be always **Optional** and it cannot be changed (otherwise db load validation would fail)

```Python hl_lines="19"
```Python hl_lines="20"
--8<-- "../docs_src/models/docs014.py"
```

Expand Down Expand Up @@ -139,7 +139,7 @@ If for whatever reason you prefer to change the name in the database but keep th
with specifying `name` parameter during Field declaration

Here you have a sample model with changed names
```Python hl_lines="18-21"
```Python hl_lines="19-22"
--8<-- "../docs_src/models/docs008.py"
```

Expand All @@ -149,7 +149,7 @@ Note that you can also change the ForeignKey column name
```

But for now you cannot change the ManyToMany column names as they go through other Model anyway.
```Python hl_lines="43"
```Python hl_lines="44"
--8<-- "../docs_src/models/docs010.py"
```

Expand Down Expand Up @@ -193,13 +193,13 @@ book = await Book.objects.first_or_404(name="123")

Note that for better IDE support and mypy checks you can provide type hints.

```Python hl_lines="15-17"
```Python hl_lines="16-18"
--8<-- "../docs_src/models/docs001.py"
```

Note that type hints are **optional** so perfectly valid `ormar` code can look like this:

```Python hl_lines="15-17"
```Python hl_lines="16-18"
--8<-- "../docs_src/models/docs012.py"
```

Expand All @@ -222,7 +222,7 @@ One is `DatabaseConnection` instance created with your database url in [sqlalche

Created instance needs to be passed to every `Model` with `ormar_config` object `database` parameter.

```Python hl_lines="3 5 11"
```Python hl_lines="4 6 12"
--8<-- "../docs_src/models/docs001.py"
```

Expand All @@ -236,7 +236,7 @@ Second dependency is sqlalchemy `MetaData` instance.

Created instance needs to be passed to every `Model` with `ormar_config` object `metadata` parameter.

```Python hl_lines="2 6 12"
```Python hl_lines="1 7 13"
--8<-- "../docs_src/models/docs001.py"
```

Expand All @@ -251,7 +251,7 @@ To ease the config management, the `OrmarConfig` class provide `copy` method.
So instead of providing the same parameters over and over again for all models
you should create a base object and use its copy in all models.

```Python hl_lines="9-12 19 28"
```Python hl_lines="10-13 20 29"
--8<-- "../docs_src/models/docs013.py"
```

Expand Down Expand Up @@ -281,7 +281,7 @@ Right now only `IndexColumns`, `UniqueColumns` and `CheckColumns` constraints ar

You can set this parameter by providing `ormar_config` object `constraints` argument.

```Python hl_lines="13-16"
```Python hl_lines="14-17"
--8<-- "../docs_src/models/docs006.py"
```

Expand All @@ -294,7 +294,7 @@ You can set this parameter by providing `ormar_config` object `constraints` argu

You can set this parameter by providing `ormar_config` object `constraints` argument.

```Python hl_lines="13-16"
```Python hl_lines="14-17"
--8<-- "../docs_src/models/docs017.py"
```

Expand All @@ -307,7 +307,7 @@ You can set this parameter by providing `ormar_config` object `constraints` argu

You can set this parameter by providing `ormar_config` object `constraints` argument.

```Python hl_lines="15-20"
```Python hl_lines="16-21"
--8<-- "../docs_src/models/docs018.py"
```

Expand All @@ -334,7 +334,7 @@ model_config = ConfigDict(validate_assignment=True, ser_json_bytes="base64")
```

So to overwrite setting or provide your own a sample model can look like following:
```Python hl_lines="16"
```Python hl_lines="17"
--8<-- "../docs_src/models/docs016.py"
```

Expand Down Expand Up @@ -415,7 +415,7 @@ There are two ways to create and persist the `Model` instance in the database.

If you plan to modify the instance in the later execution of your program you can initiate your `Model` as a normal class and later await a `save()` call.

```Python hl_lines="29-30"
```Python hl_lines="30-31"
--8<-- "../docs_src/models/docs007.py"
```

Expand All @@ -425,7 +425,7 @@ For creating multiple objects at once a `bulk_create()` QuerySet's method is ava

Each model has a `QuerySet` initialised as `objects` parameter

```Python hl_lines="32"
```Python hl_lines="33"
--8<-- "../docs_src/models/docs007.py"
```

Expand Down
6 changes: 3 additions & 3 deletions docs/models/internals.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ All `Model` classes inherit from `pydantic.BaseModel` so you can access all norm

For example to list pydantic model fields you can:

```Python hl_lines="20"
```Python hl_lines="21"
--8<-- "../docs_src/models/docs003.py"
```

Expand All @@ -24,7 +24,7 @@ To access auto created sqlalchemy table you can use `Model.ormar_config.table` p

For example to list table columns you can:

```Python hl_lines="24"
```Python hl_lines="25"
--8<-- "../docs_src/models/docs004.py"
```

Expand All @@ -40,7 +40,7 @@ To access ormar `Fields` you can use `Model.ormar_config.model_fields` parameter

For example to list table model fields you can:

```Python hl_lines="22"
```Python hl_lines="23"
--8<-- "../docs_src/models/docs005.py"
```

Expand Down
4 changes: 2 additions & 2 deletions docs/mypy.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ To provide better errors check you should use mypy with pydantic [plugin][plugin

Please use notation introduced in version 0.4.0.

```Python hl_lines="15-17"
```Python hl_lines="16-18"
--8<-- "../docs_src/models/docs012.py"
```

Note that above example is not using the type hints, so further operations with mypy might fail, depending on the context.

Preferred notation should look liked this:

```Python hl_lines="15-17"
```Python hl_lines="16-18"
--8<-- "../docs_src/models/docs001.py"
```

Expand Down
4 changes: 2 additions & 2 deletions docs/queries/create.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ assert album == album2

Updates the model, or in case there is no match in database creates a new one.

```Python hl_lines="43-51"
```Python hl_lines="44-52"
--8<-- "../docs_src/queries/docs003.py"
```

Expand All @@ -125,7 +125,7 @@ Allows you to create multiple objects at once.

A valid list of `Model` objects needs to be passed.

```python hl_lines="29-35"
```python hl_lines="30-37"
--8<-- "../docs_src/queries/docs004.py"
```

Expand Down
2 changes: 1 addition & 1 deletion docs/queries/delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ If you do not provide this flag or a filter a `QueryDefinitionError` will be rai

Return number of rows deleted.

```python hl_lines="43-47"
```python hl_lines="44-48"
--8<-- "../docs_src/queries/docs005.py"
```

Expand Down
4 changes: 2 additions & 2 deletions docs/queries/update.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ If you do not provide this flag or a filter a `QueryDefinitionError` will be rai

Return number of rows updated.

```Python hl_lines="45-47"
```Python hl_lines="46-48"
--8<-- "../docs_src/queries/docs002.py"
```

Expand All @@ -44,7 +44,7 @@ Return number of rows updated.

Updates the model, or in case there is no match in database creates a new one.

```Python hl_lines="43-51"
```Python hl_lines="44-52"
--8<-- "../docs_src/queries/docs003.py"
```

Expand Down
6 changes: 3 additions & 3 deletions docs/relations/foreign-key.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Sqlalchemy column and type are automatically taken from target `Model`.

To define a relation add `ForeignKey` field that points to related `Model`.

```Python hl_lines="30"
```Python hl_lines="31"
--8<-- "../docs_src/fields/docs003.py"
```

Expand All @@ -24,7 +24,7 @@ To define a relation add `ForeignKey` field that points to related `Model`.

By default it's child (source) `Model` name + s, like courses in snippet below:

```Python hl_lines="33 40"
```Python hl_lines="34 41"
--8<-- "../docs_src/fields/docs001.py"
```

Expand Down Expand Up @@ -173,7 +173,7 @@ To read which methods of QuerySet are available read below [querysetproxy][query

You can overwrite related model field name by providing `related_name` parameter like below:

```Python hl_lines="27-29 35"
```Python hl_lines="28-30 36"
--8<-- "../docs_src/fields/docs002.py"
```

Expand Down
2 changes: 1 addition & 1 deletion docs/relations/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ To read more about methods, possibilities, definition etc. please read the subse

To define many-to-one relation use `ForeignKey` field.

```Python hl_lines="26"
```Python hl_lines="27"
--8<-- "../docs_src/relations/docs003.py"
```

Expand Down
6 changes: 3 additions & 3 deletions docs/relations/many-to-many.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Sqlalchemy column and Type are automatically taken from target `Model`.

## Defining Models

```Python hl_lines="34"
```Python hl_lines="35"
--8<-- "../docs_src/relations/docs002.py"
```

Expand Down Expand Up @@ -139,7 +139,7 @@ assert len(categories) == 1
Optionally if you want to add additional fields you can explicitly create and pass
the through model class.

```Python hl_lines="19-24 32"
```Python hl_lines="20-25 33"
--8<-- "../docs_src/relations/docs004.py"
```

Expand Down Expand Up @@ -232,7 +232,7 @@ so it's useful only when additional fields are provided on `Through` model.

In a sample model setup as following:

```Python hl_lines="19-24 32"
```Python hl_lines="20-25 33"
--8<-- "../docs_src/relations/docs004.py"
```

Expand Down
4 changes: 2 additions & 2 deletions docs/relations/queryset-proxy.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ provided Through model.

Given sample like this:

```Python hl_lines="19-24 32"
```Python hl_lines="20-25 33"
--8<-- "../docs_src/relations/docs004.py"
```

Expand Down Expand Up @@ -174,7 +174,7 @@ Updates the related model with provided keyword arguments, return number of upda
Note that for `ManyToMany` relations update can also accept an argument with through field
name and a dictionary of fields.

```Python hl_lines="19-24 32"
```Python hl_lines="20-25 33"
--8<-- "../docs_src/relations/docs004.py"
```

Expand Down
6 changes: 3 additions & 3 deletions docs/signals.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ You can for example define a trigger that will set `album.is_best_seller` status

Import `pre_update` decorator, for list of currently available decorators/ signals check below.

```Python hl_lines="6"
```Python hl_lines="7"
--8<-- "../docs_src/signals/docs002.py"
```

Expand All @@ -54,7 +54,7 @@ for which you want to run the signal receiver.

Currently there is no way to set signal for all models at once without explicitly passing them all into registration of receiver.

```Python hl_lines="30-33"
```Python hl_lines="31-34"
--8<-- "../docs_src/signals/docs002.py"
```

Expand All @@ -65,7 +65,7 @@ Currently there is no way to set signal for all models at once without explicitl
Note that our newly created function has instance and class of the instance so you can easily run database
queries inside your receivers if you want to.

```Python hl_lines="43-50"
```Python hl_lines="44-51"
--8<-- "../docs_src/signals/docs002.py"
```

Expand Down
Loading
Loading