Skip to content

Commit d6fb163

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 9f93a95 + 7999a51 commit d6fb163

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1424
-614
lines changed

.flake8

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[flake8]
2+
max-line-length = 88
3+
select = C,E,F,W,B,B9
4+
ignore = B008, E203, W503, CFQ002
5+
import-order-style = pycharm

.github/scripts/releases.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,32 @@
33
from github import Github
44
from github.GitRelease import GitRelease
55

6-
GITHUB_REPOSITORY = environ.get('GITHUB_REPOSITORY', 'awtkns/fastapi-crudrouter')
7-
GITHUB_TOKEN = environ.get('GITHUB_TOKEN') or environ.get('GH_TOKEN')
6+
GITHUB_REPOSITORY = environ.get("GITHUB_REPOSITORY", "awtkns/fastapi-crudrouter")
7+
GITHUB_TOKEN = environ.get("GITHUB_TOKEN") or environ.get("GH_TOKEN")
88
FILE_PATH = "docs/en/docs/releases.md"
99
COMMIT_MESSAGE = "🤖 auto update releases.md"
1010

1111
gh = Github(GITHUB_TOKEN)
1212

1313

1414
def generate_header(r: GitRelease, separator: bool = False):
15-
header = ''
15+
header = ""
1616
if separator:
1717
header += "\n\n---\n"
1818

19-
return header + f"""
19+
return (
20+
header
21+
+ f"""
2022
## [{r.title}]({r.html_url}){" { .releases } "}
2123
{r.created_at.date()}
2224
"""
25+
)
2326

2427

25-
if __name__ == '__main__':
28+
if __name__ == "__main__":
2629
repo = gh.get_repo(GITHUB_REPOSITORY)
2730

28-
new_content = ''
31+
new_content = ""
2932
first = False
3033
for r in repo.get_releases():
3134
if not r.draft:

.github/workflows/lint.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Lint
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
lint:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
- name: Set up Python
15+
uses: actions/setup-python@v2
16+
- name: Run Black Code Formatter
17+
uses: psf/black@stable
18+
- name: Install dependencies
19+
run: |
20+
python -m pip install --upgrade pip
21+
pip install -r tests/dev.requirements.txt
22+
- name: Check Typing with mypy
23+
run: |
24+
mypy fastapi_crudrouter
25+
- name: Lint with flake8
26+
run: |
27+
flake8 fastapi_crudrouter

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ venv/
4848
ENV/
4949
env.bak/
5050
venv.bak/
51+
p38venv/
5152

5253
# Databases
5354
*.db

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ likely grow in future releases.
6868
- In Memory ([docs](https://fastapi-crudrouter.awtkns.com/backends/memory/))
6969
- SQLAlchemy ([docs](https://fastapi-crudrouter.awtkns.com/backends/sqlalchemy/))
7070
- Databases (async) ([docs](https://fastapi-crudrouter.awtkns.com/backends/async/))
71+
- Ormar (async) ([docs](https://fastapi-crudrouter.awtkns.com/backends/ormar/))
7172
- Tortoise ORM (async) ([docs](https://fastapi-crudrouter.awtkns.com/backends/tortoise/))
7273

7374
## OpenAPI Support

docs/en/docs/backends/ormar.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
When generating routes, the `OrmarCRUDRouter` will automatically tie into your database
2+
using your [ormar](https://collerek.github.io/ormar/) models. To use it, simply pass your ormar database model as the schema.
3+
4+
## Simple Example
5+
6+
Below is an example assuming that you have already imported and created all the required
7+
models.
8+
9+
```python
10+
router = OrmarCRUDRouter(
11+
schema=MyOrmarModel,
12+
create_schema=Optional[MyPydanticCreateModel],
13+
update_schema=Optional[MyPydanticUpdateModel]
14+
)
15+
16+
app.include_router(router)
17+
```
18+
19+
!!! note The `create_schema` should not include the *primary id* field as this be
20+
generated by the database.
21+
22+
## Full Example
23+
24+
```python
25+
# example.py
26+
import databases
27+
import ormar
28+
import sqlalchemy
29+
import uvicorn
30+
from fastapi import FastAPI
31+
32+
from fastapi_crudrouter import OrmarCRUDRouter
33+
34+
DATABASE_URL = "sqlite:///./test.db"
35+
database = databases.Database(DATABASE_URL)
36+
metadata = sqlalchemy.MetaData()
37+
38+
app = FastAPI()
39+
40+
41+
@app.on_event("startup")
42+
async def startup():
43+
await database.connect()
44+
45+
46+
@app.on_event("shutdown")
47+
async def shutdown():
48+
await database.disconnect()
49+
50+
51+
class BaseMeta(ormar.ModelMeta):
52+
metadata = metadata
53+
database = database
54+
55+
56+
def _setup_database():
57+
# if you do not have the database run this once
58+
engine = sqlalchemy.create_engine(DATABASE_URL)
59+
metadata.drop_all(engine)
60+
metadata.create_all(engine)
61+
return engine, database
62+
63+
64+
class Potato(ormar.Model):
65+
class Meta(BaseMeta):
66+
pass
67+
68+
id = ormar.Integer(primary_key=True)
69+
thickness = ormar.Float()
70+
mass = ormar.Float()
71+
color = ormar.String(max_length=255)
72+
type = ormar.String(max_length=255)
73+
74+
75+
app.include_router(
76+
OrmarCRUDRouter(
77+
schema=Potato,
78+
prefix="potato",
79+
)
80+
)
81+
82+
if __name__ == "__main__":
83+
uvicorn.run("example:app", host="127.0.0.1", port=5000, log_level="info")
84+
```

docs/en/docs/backends/tortoise.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ your database using your [Tortoise](https://tortoise-orm.readthedocs.io/en/lates
33
[pydantic](https://pydantic-docs.helpmanual.io/) schema, your Tortoise database model to it, and register Tortoise ORM with your FastAPI App.
44

55
!!! warning
6-
To use the `SQLAlchemyCRUDRouter`, [Tortoise ORM](https://pypi.org/project/tortoise-orm/) must be first installed.
6+
To use the `TortoiseCRUDRouter`, [Tortoise ORM](https://pypi.org/project/tortoise-orm/) must be first installed.
77

88
## Simple Example
99
Below is an example assuming that you have already imported and created all the required models.

docs/en/docs/contributing.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,28 @@ $ pytest
4040

4141
</div>
4242

43+
### Linting, formatting and type testing
44+
45+
With `dev.requirements.txt` installed above you also install tools to lint, format and static type check the project.
46+
47+
To format the project run:
48+
49+
```
50+
black fastapi_crudrouter tests
51+
```
52+
53+
To check styles, imports, annotations, pep8 etc. run:
54+
55+
```
56+
flake8 fastapi_crudrouter
57+
```
58+
59+
To check static types annotations run:
60+
61+
```
62+
mypy fastapi_crudrouter tests
63+
```
64+
4365
### Documentation
4466
Crudrouter's documentation was built using [mkdocs-material](https://squidfunk.github.io/mkdocs-material/). To start the development
4567
documentation server, please first install mkdocs-material and then run the server as shown below.

docs/en/docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ likely grow in future releases.
7474
- In Memory ([docs](https://fastapi-crudrouter.awtkns.com/backends/memory/))
7575
- SQLAlchemy ([docs](https://fastapi-crudrouter.awtkns.com/backends/sqlalchemy/))
7676
- Databases (async) ([docs](https://fastapi-crudrouter.awtkns.com/backends/async/))
77+
- Ormar (async) ([docs](https://fastapi-crudrouter.awtkns.com/backends/ormar/))
7778
- Tortoise ORM (async) ([docs](https://fastapi-crudrouter.awtkns.com/backends/tortoise/))
7879

7980
## OpenAPI Support

docs/en/mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ nav:
2626
- In Memory: backends/memory.md
2727
- SQLAlchemy: backends/sqlalchemy.md
2828
- Databases (async): backends/async.md
29+
- Ormar (async): backends/ormar.md
2930
- Tortoise (async): backends/tortoise.md
3031
- Dependencies: dependencies.md
3132
- Contributing: contributing.md

fastapi_crudrouter/__init__.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,15 @@
1-
from .core import MemoryCRUDRouter, SQLAlchemyCRUDRouter, DatabasesCRUDRouter, TortoiseCRUDRouter
1+
from .core import (
2+
DatabasesCRUDRouter,
3+
MemoryCRUDRouter,
4+
OrmarCRUDRouter,
5+
SQLAlchemyCRUDRouter,
6+
TortoiseCRUDRouter,
7+
)
8+
9+
__all__ = [
10+
"MemoryCRUDRouter",
11+
"SQLAlchemyCRUDRouter",
12+
"DatabasesCRUDRouter",
13+
"TortoiseCRUDRouter",
14+
"OrmarCRUDRouter",
15+
]

fastapi_crudrouter/core/__init__.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
from . import _utils
2-
from ._base import CRUDGenerator, NOT_FOUND
3-
2+
from ._base import CRUDGenerator, NOT_FOUND, T
3+
from .databases import DatabasesCRUDRouter
44
from .mem import MemoryCRUDRouter
5+
from .ormar import OrmarCRUDRouter
56
from .sqlalchemy import SQLAlchemyCRUDRouter
6-
from .databases import DatabasesCRUDRouter
77
from .tortoise import TortoiseCRUDRouter
8+
9+
__all__ = [
10+
"_utils",
11+
"CRUDGenerator",
12+
"NOT_FOUND",
13+
"T",
14+
"MemoryCRUDRouter",
15+
"SQLAlchemyCRUDRouter",
16+
"DatabasesCRUDRouter",
17+
"TortoiseCRUDRouter",
18+
"OrmarCRUDRouter",
19+
]

0 commit comments

Comments
 (0)