add get_db
method
This commit is contained in:
parent
79ec14516a
commit
fdea61b784
@ -1,6 +1,6 @@
|
|||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
import models
|
import models
|
||||||
from database import engine
|
from database import engine, SessionLocal
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
@ -8,6 +8,14 @@ app = FastAPI()
|
|||||||
models.Base.metadata.create_all(bind=engine)
|
models.Base.metadata.create_all(bind=engine)
|
||||||
|
|
||||||
|
|
||||||
|
def get_db():
|
||||||
|
db = SessionLocal()
|
||||||
|
try:
|
||||||
|
yield db
|
||||||
|
finally:
|
||||||
|
db.close()
|
||||||
|
|
||||||
|
|
||||||
class Post:
|
class Post:
|
||||||
"""Post is a single forum post or reply"""
|
"""Post is a single forum post or reply"""
|
||||||
id: int
|
id: int
|
||||||
|
Loading…
Reference in New Issue
Block a user