Ver a proveniência
Merge pull request #3 from shinbay-almaz/Madi
added ORM, configured database
main
Madiwka
há 1 ano
committed by
GitHub
ascendente
cometimento
c0f7a08945
Não foi encontrada uma chave conhecida para esta assinatura, na base de dados
ID da chave GPG: 4AEE18F83AFDEB23
4 ficheiros alterados com
46 adições e
1 eliminações
-
app/core/config.py
-
app/db/base_model.py
-
app/db/session.py
-
app/main.py
|
|
@@ -0,0 +1,12 @@ |
|
|
|
class Settings: |
|
|
|
PROJECT_NAME:str = "VMS" |
|
|
|
PROJECT_VERSION:str = "1.0.0" |
|
|
|
|
|
|
|
POSTGRES_USER : str = "VMSBase" |
|
|
|
POSTGRES_PASSWORD = "VMSBasePass" |
|
|
|
POSTGRES_SERVER : str = "localhost" |
|
|
|
POSTGRES_PORT : str = "5432" |
|
|
|
POSTGRES_DB : str = "VMSData" |
|
|
|
DATABASE_URL = f"postgresql://{POSTGRES_USER}:{POSTGRES_PASSWORD}@{POSTGRES_SERVER}:{POSTGRES_PORT}/{POSTGRES_DB}" |
|
|
|
|
|
|
|
settings = Settings() |
|
|
@@ -0,0 +1,11 @@ |
|
|
|
from typing import Any |
|
|
|
from sqlalchemy.ext.declarative import declared_attr |
|
|
|
from sqlalchemy.orm import as_declarative |
|
|
|
|
|
|
|
|
|
|
|
@as_declarative() |
|
|
|
class Base: |
|
|
|
id: Any |
|
|
|
__name__: str |
|
|
|
def __tablename__(cls) -> str: |
|
|
|
return cls.__name__.lower() |
|
|
@@ -0,0 +1,11 @@ |
|
|
|
from sqlalchemy import create_engine |
|
|
|
from sqlalchemy.orm import sessionmaker |
|
|
|
from core.config import settings |
|
|
|
|
|
|
|
|
|
|
|
SQLALCHEMY_DATABASE_URL = settings.DATABASE_URL |
|
|
|
engine = create_engine(SQLALCHEMY_DATABASE_URL) |
|
|
|
print(SQLALCHEMY_DATABASE_URL) |
|
|
|
|
|
|
|
SessionLocal = sessionmaker(autocommit=False,autoflush=False,bind=engine) |
|
|
|
|
|
|
@@ -1,6 +1,17 @@ |
|
|
|
from fastapi import FastAPI |
|
|
|
from core.config import settings |
|
|
|
from db.session import engine |
|
|
|
from db.base_model import Base |
|
|
|
|
|
|
|
app = FastAPI() |
|
|
|
|
|
|
|
def startup(): #start the project, and create the tables |
|
|
|
app = FastAPI(title=settings.PROJECT_NAME,version=settings.PROJECT_VERSION) |
|
|
|
Base.metadata.create_all(bind=engine) |
|
|
|
return app |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app = startup() |
|
|
|
|
|
|
|
@app.get("/") |
|
|
|
def root(): |
|
|
|