Skip to content

Commit 80c8a68

Browse files
committed
✨ Gino Ready for Release
1 parent a6709c8 commit 80c8a68

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

docs/en/docs/backends/gino.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Asynchronous routes will be automatically generated when using the `GinoCRUDRouter`. To use it, you must pass a
2+
[pydantic](https://pydantic-docs.helpmanual.io/) model, your SQLAlchemy Table, and the databases database.
3+
This CRUDRouter is intended to be used with the python [Gino](https://python-gino.org/) library. An example
4+
of how to use [Gino](https://python-gino.org/) with FastAPI can be found both
5+
[here](https://python-gino.org/docs/en/1.0/tutorials/fastapi.html) and below.
6+
7+
!!! warning
8+
To use the `GinoCRUDRouter`, Databases **and** SQLAlchemy must be first installed.
9+
10+
## Minimal Example
11+
Below is a minimal example assuming that you have already imported and created
12+
all the required models and database connections.
13+
14+
```python
15+
router = GinoCRUDRouter(
16+
schema=MyPydanticModel,
17+
db=db,
18+
db_model=MyModel
19+
)
20+
app.include_router(router)
21+
```

docs/en/mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ nav:
3232
- In Memory: backends/memory.md
3333
- SQLAlchemy: backends/sqlalchemy.md
3434
- Databases (async): backends/async.md
35+
- Gino (async): backends/gino.md
3536
- Ormar (async): backends/ormar.md
3637
- Tortoise (async): backends/tortoise.md
3738
- Routing: routing.md

fastapi_crudrouter/core/gino_starlette.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
from ._types import PYDANTIC_SCHEMA as SCHEMA
88

99
try:
10-
import asyncpg
10+
from asyncpg.exceptions import UniqueViolationError
1111
from gino import Gino
12-
1312
from sqlalchemy.exc import IntegrityError
1413
from sqlalchemy.ext.declarative import DeclarativeMeta as Model
1514
except ImportError:
@@ -96,7 +95,7 @@ async def route(
9695
async with self.db.transaction():
9796
db_model: Model = await self.db_model.create(**model.dict())
9897
return db_model
99-
except (IntegrityError, asyncpg.exceptions.UniqueViolationError):
98+
except (IntegrityError, UniqueViolationError):
10099
raise HTTPException(422, "Key already exists")
101100

102101
return route
@@ -113,7 +112,7 @@ async def route(
113112
await db_model.update(**model).apply()
114113

115114
return db_model
116-
except (IntegrityError, asyncpg.exceptions.UniqueViolationError) as e:
115+
except (IntegrityError, UniqueViolationError) as e:
117116
raise HTTPException(422, ", ".join(e.args))
118117

119118
return route

tests/conf/dev.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
POSTGRES_HOST=db
1+
POSTGRES_HOST=localhost
22
POSTGRES_DB=test
33
POSTGRES_USER=postgres
44
POSTGRES_PASSWORD=password

0 commit comments

Comments
 (0)