every changed processed
This commit is contained in:
parent
8cefa60d3a
commit
9e64832ba0
6 changed files with 138 additions and 135 deletions
28
config.py
28
config.py
|
|
@ -4,18 +4,30 @@ from sqlalchemy.orm import sessionmaker
|
|||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from passlib.context import CryptContext
|
||||
from sqlmodel import SQLModel, Field, Session
|
||||
from dotenv import load_dotenv
|
||||
import os
|
||||
|
||||
load_dotenv()
|
||||
|
||||
|
||||
Base = declarative_base() #basic class for declarative models
|
||||
# Veritabanı URL'sini oluştur
|
||||
DATABASE_URL = (
|
||||
f"postgresql://{os.getenv('USERNAME_DB')}:"
|
||||
f"{os.getenv('PASSWORD_DB')}@"
|
||||
f"{os.getenv('HOST_DB')}:"
|
||||
f"{os.getenv('PORT_DB')}/"
|
||||
f"{os.getenv('NAME_DB')}"
|
||||
)
|
||||
|
||||
engine = create_engine(DATABASE_URL, echo=False)
|
||||
def init_db():
|
||||
SQLModel.metadata.create_all(engine)
|
||||
|
||||
def get_session_db():
|
||||
with Session(engine) as session:
|
||||
yield session
|
||||
|
||||
DATABASE_URL = f"postgresql://{os.getenv('USERNAME_DB')}:{os.getenv('PASSWORD_DB')}@{os.getenv('HOST_DB')}:{os.getenv('PORT_DB')}/{os.getenv('NAME_DB')}"
|
||||
engine = create_engine(DATABASE_URL)
|
||||
SessionLocal = sessionmaker(bind=engine)
|
||||
Base.metadata.create_all(bind=engine)
|
||||
|
||||
|
||||
### SECRET KEY ###
|
||||
|
|
@ -34,6 +46,9 @@ origins = [
|
|||
]
|
||||
|
||||
app = FastAPI()
|
||||
@app.on_event("startup")
|
||||
def on_startup():
|
||||
init_db()
|
||||
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
|
|
@ -42,3 +57,6 @@ app.add_middleware(
|
|||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue