Skip to content

Commit 21e4a80

Browse files
committed
update base branch
1 parent f6c58fe commit 21e4a80

13 files changed

+2
-373
lines changed

.gitignore

-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
__pycache__
22
env
3-
htmlcov
4-
.coverage

README.md

-19
Original file line numberDiff line numberDiff line change
@@ -1,20 +1 @@
11
# FastAPI + SQLModel + Alembic
2-
3-
Sample FastAPI project that uses async SQLAlchemy, SQLModel, Postgres, Alembic, and Docker.
4-
5-
## Getting Started
6-
7-
```sh
8-
$ docker-compose up -d --build
9-
$ docker-compose exec web alembic upgrade head
10-
```
11-
12-
Sanity check: [http://localhost:8004/ping](http://localhost:8004/ping)
13-
14-
Add a song:
15-
16-
```sh
17-
$ curl -d '{"name":"Midnight Fit", "artist":"Mogwai", "year":"2021"}' -H "Content-Type: application/json" -X POST http://localhost:8004/songs
18-
```
19-
20-
Get all songs: [http://localhost:8004/songs](http://localhost:8004/songs)

docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ services:
1010
ports:
1111
- 8004:8000
1212
environment:
13-
- DATABASE_URL=postgresql+asyncpg://postgres:postgres@db:5432/foo
13+
- DATABASE_URL=postgresql://postgres:postgres@db:5432/foo
1414
depends_on:
1515
- db
1616

project/alembic.ini

-100
This file was deleted.

project/app/db.py

-25
This file was deleted.

project/app/main.py

+1-21
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,8 @@
1-
from fastapi import Depends, FastAPI
2-
from sqlalchemy import select
3-
from sqlalchemy.ext.asyncio import AsyncSession
4-
5-
from app.db import get_session
6-
from app.models import Song, SongCreate
1+
from fastapi import FastAPI
72

83
app = FastAPI()
94

105

116
@app.get("/ping")
127
async def pong():
138
return {"ping": "pong!"}
14-
15-
16-
@app.get("/songs", response_model=list[Song])
17-
async def get_songs(session: AsyncSession = Depends(get_session)):
18-
result = await session.execute(select(Song))
19-
songs = result.scalars().all()
20-
return [Song(name=song.name, artist=song.artist, year=song.year, id=song.id) for song in songs]
21-
22-
23-
@app.post("/songs")
24-
async def add_song(song: SongCreate, session: AsyncSession = Depends(get_session)):
25-
song = Song(name=song.name, artist=song.artist, year=song.year)
26-
session.add(song)
27-
await session.commit()
28-
return song

project/app/models.py

-15
This file was deleted.

project/migrations/README

-1
This file was deleted.

project/migrations/env.py

-88
This file was deleted.

project/migrations/script.py.mako

-25
This file was deleted.

project/migrations/versions/94598cb1fa7b_add_year.py

-31
This file was deleted.

project/migrations/versions/bf9bd33c0c06_init.py

-40
This file was deleted.

0 commit comments

Comments
 (0)