Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
awtkns committed Mar 26, 2021
2 parents 9f93a95 + 7999a51 commit d6fb163
Show file tree
Hide file tree
Showing 45 changed files with 1,424 additions and 614 deletions.
5 changes: 5 additions & 0 deletions .flake8
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
15 changes: 9 additions & 6 deletions .github/scripts/releases.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,32 @@
from github import Github
from github.GitRelease import GitRelease

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

gh = Github(GITHUB_TOKEN)


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

return header + f"""
return (
header
+ f"""
## [{r.title}]({r.html_url}){" { .releases } "}
{r.created_at.date()}
"""
)


if __name__ == '__main__':
if __name__ == "__main__":
repo = gh.get_repo(GITHUB_REPOSITORY)

new_content = ''
new_content = ""
first = False
for r in repo.get_releases():
if not r.draft:
Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/lint.yml
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ venv/
ENV/
env.bak/
venv.bak/
p38venv/

# Databases
*.db
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ likely grow in future releases.
- In Memory ([docs](https://fastapi-crudrouter.awtkns.com/backends/memory/))
- SQLAlchemy ([docs](https://fastapi-crudrouter.awtkns.com/backends/sqlalchemy/))
- Databases (async) ([docs](https://fastapi-crudrouter.awtkns.com/backends/async/))
- Ormar (async) ([docs](https://fastapi-crudrouter.awtkns.com/backends/ormar/))
- Tortoise ORM (async) ([docs](https://fastapi-crudrouter.awtkns.com/backends/tortoise/))

## OpenAPI Support
Expand Down
84 changes: 84 additions & 0 deletions docs/en/docs/backends/ormar.md
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")
```
2 changes: 1 addition & 1 deletion docs/en/docs/backends/tortoise.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ your database using your [Tortoise](https://tortoise-orm.readthedocs.io/en/lates
[pydantic](https://pydantic-docs.helpmanual.io/) schema, your Tortoise database model to it, and register Tortoise ORM with your FastAPI App.

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

## Simple Example
Below is an example assuming that you have already imported and created all the required models.
Expand Down
22 changes: 22 additions & 0 deletions docs/en/docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,28 @@ $ pytest

</div>

### Linting, formatting and type testing

With `dev.requirements.txt` installed above you also install tools to lint, format and static type check the project.

To format the project run:

```
black fastapi_crudrouter tests
```

To check styles, imports, annotations, pep8 etc. run:

```
flake8 fastapi_crudrouter
```

To check static types annotations run:

```
mypy fastapi_crudrouter tests
```

### Documentation
Crudrouter's documentation was built using [mkdocs-material](https://squidfunk.github.io/mkdocs-material/). To start the development
documentation server, please first install mkdocs-material and then run the server as shown below.
Expand Down
1 change: 1 addition & 0 deletions docs/en/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ likely grow in future releases.
- In Memory ([docs](https://fastapi-crudrouter.awtkns.com/backends/memory/))
- SQLAlchemy ([docs](https://fastapi-crudrouter.awtkns.com/backends/sqlalchemy/))
- Databases (async) ([docs](https://fastapi-crudrouter.awtkns.com/backends/async/))
- Ormar (async) ([docs](https://fastapi-crudrouter.awtkns.com/backends/ormar/))
- Tortoise ORM (async) ([docs](https://fastapi-crudrouter.awtkns.com/backends/tortoise/))

## OpenAPI Support
Expand Down
1 change: 1 addition & 0 deletions docs/en/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ nav:
- In Memory: backends/memory.md
- SQLAlchemy: backends/sqlalchemy.md
- Databases (async): backends/async.md
- Ormar (async): backends/ormar.md
- Tortoise (async): backends/tortoise.md
- Dependencies: dependencies.md
- Contributing: contributing.md
Expand Down
16 changes: 15 additions & 1 deletion fastapi_crudrouter/__init__.py
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",
]
18 changes: 15 additions & 3 deletions fastapi_crudrouter/core/__init__.py
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",
]
Loading

1 comment on commit d6fb163

@vercel
Copy link

@vercel vercel bot commented on d6fb163 Mar 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.