-
-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master'
- Loading branch information
Showing
45 changed files
with
1,424 additions
and
614 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[flake8] | ||
max-line-length = 88 | ||
select = C,E,F,W,B,B9 | ||
ignore = B008, E203, W503, CFQ002 | ||
import-order-style = pycharm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Lint | ||
|
||
on: | ||
push: | ||
branches: [ master ] | ||
pull_request: | ||
branches: [ master ] | ||
|
||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
- name: Run Black Code Formatter | ||
uses: psf/black@stable | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r tests/dev.requirements.txt | ||
- name: Check Typing with mypy | ||
run: | | ||
mypy fastapi_crudrouter | ||
- name: Lint with flake8 | ||
run: | | ||
flake8 fastapi_crudrouter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,7 @@ venv/ | |
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
p38venv/ | ||
|
||
# Databases | ||
*.db | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
When generating routes, the `OrmarCRUDRouter` will automatically tie into your database | ||
using your [ormar](https://collerek.github.io/ormar/) models. To use it, simply pass your ormar database model as the schema. | ||
|
||
## Simple Example | ||
|
||
Below is an example assuming that you have already imported and created all the required | ||
models. | ||
|
||
```python | ||
router = OrmarCRUDRouter( | ||
schema=MyOrmarModel, | ||
create_schema=Optional[MyPydanticCreateModel], | ||
update_schema=Optional[MyPydanticUpdateModel] | ||
) | ||
|
||
app.include_router(router) | ||
``` | ||
|
||
!!! note The `create_schema` should not include the *primary id* field as this be | ||
generated by the database. | ||
|
||
## Full Example | ||
|
||
```python | ||
# example.py | ||
import databases | ||
import ormar | ||
import sqlalchemy | ||
import uvicorn | ||
from fastapi import FastAPI | ||
|
||
from fastapi_crudrouter import OrmarCRUDRouter | ||
|
||
DATABASE_URL = "sqlite:///./test.db" | ||
database = databases.Database(DATABASE_URL) | ||
metadata = sqlalchemy.MetaData() | ||
|
||
app = FastAPI() | ||
|
||
|
||
@app.on_event("startup") | ||
async def startup(): | ||
await database.connect() | ||
|
||
|
||
@app.on_event("shutdown") | ||
async def shutdown(): | ||
await database.disconnect() | ||
|
||
|
||
class BaseMeta(ormar.ModelMeta): | ||
metadata = metadata | ||
database = database | ||
|
||
|
||
def _setup_database(): | ||
# if you do not have the database run this once | ||
engine = sqlalchemy.create_engine(DATABASE_URL) | ||
metadata.drop_all(engine) | ||
metadata.create_all(engine) | ||
return engine, database | ||
|
||
|
||
class Potato(ormar.Model): | ||
class Meta(BaseMeta): | ||
pass | ||
|
||
id = ormar.Integer(primary_key=True) | ||
thickness = ormar.Float() | ||
mass = ormar.Float() | ||
color = ormar.String(max_length=255) | ||
type = ormar.String(max_length=255) | ||
|
||
|
||
app.include_router( | ||
OrmarCRUDRouter( | ||
schema=Potato, | ||
prefix="potato", | ||
) | ||
) | ||
|
||
if __name__ == "__main__": | ||
uvicorn.run("example:app", host="127.0.0.1", port=5000, log_level="info") | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,15 @@ | ||
from .core import MemoryCRUDRouter, SQLAlchemyCRUDRouter, DatabasesCRUDRouter, TortoiseCRUDRouter | ||
from .core import ( | ||
DatabasesCRUDRouter, | ||
MemoryCRUDRouter, | ||
OrmarCRUDRouter, | ||
SQLAlchemyCRUDRouter, | ||
TortoiseCRUDRouter, | ||
) | ||
|
||
__all__ = [ | ||
"MemoryCRUDRouter", | ||
"SQLAlchemyCRUDRouter", | ||
"DatabasesCRUDRouter", | ||
"TortoiseCRUDRouter", | ||
"OrmarCRUDRouter", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,19 @@ | ||
from . import _utils | ||
from ._base import CRUDGenerator, NOT_FOUND | ||
|
||
from ._base import CRUDGenerator, NOT_FOUND, T | ||
from .databases import DatabasesCRUDRouter | ||
from .mem import MemoryCRUDRouter | ||
from .ormar import OrmarCRUDRouter | ||
from .sqlalchemy import SQLAlchemyCRUDRouter | ||
from .databases import DatabasesCRUDRouter | ||
from .tortoise import TortoiseCRUDRouter | ||
|
||
__all__ = [ | ||
"_utils", | ||
"CRUDGenerator", | ||
"NOT_FOUND", | ||
"T", | ||
"MemoryCRUDRouter", | ||
"SQLAlchemyCRUDRouter", | ||
"DatabasesCRUDRouter", | ||
"TortoiseCRUDRouter", | ||
"OrmarCRUDRouter", | ||
] |
Oops, something went wrong.
d6fb163
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: