This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@app.teardown_appcontext | |
def remove_db_session(exception=None): | |
db_session.remove() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import date | |
from pydantic import BaseModel | |
class Record(BaseModel): | |
id: int | |
date: date | |
country: str | |
cases: int | |
deaths: int |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from sqlalchemy import create_engine | |
from sqlalchemy.ext.declarative import declarative_base | |
from sqlalchemy.orm import sessionmaker | |
SQLALCHEMY_DATABASE_URL = os.getenv("DB_CONN") | |
engine = create_engine(SQLALCHEMY_DATABASE_URL) | |
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sqlalchemy import Column, Integer, String | |
from sqlalchemy.types import Date | |
from .database import Base | |
class Record(Base): | |
__tablename__ = "Records" | |
id = Column(Integer, primary_key=True, index=True) | |
date = Column(Date) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import List | |
from fastapi import Depends, FastAPI, HTTPException | |
from fastapi.middleware.cors import CORSMiddleware | |
from sqlalchemy.orm import Session | |
from starlette.responses import RedirectResponse | |
from . import models, schemas | |
from .database import SessionLocal, engine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
import datetime | |
from app import models | |
from app.database import SessionLocal, engine | |
db = SessionLocal() | |
models.Base.metadata.create_all(bind=engine) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@app.get("/records/", response_model=List[schemas.Record]) | |
def show_records(db: Session = Depends(get_db)): | |
records = db.query(models.Record).all() | |
return records |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
app = Flask(__name__) | |
app.config["SQLALCHEMY_DATABASE_URI"] = os.getenv("JAWSDB_URL", "sqlite:///pets.sqlite") | |
db = SQLAlchemy(app) | |
class DictMixIn: | |
def to_dict(self): | |
return { | |
column.name: getattr(self, column.name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM python:3.7-slim | |
ENV APP_HOME /app | |
WORKDIR $APP_HOME | |
COPY . ./ | |
RUN pip install pipenv | |
RUN pipenv install --deploy --system | |
CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 app.main:app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
import datetime | |
from app import models | |
from app.database import SessionLocal, engine | |
db = SessionLocal() | |
models.Base.metadata.create_all(bind=engine) |
OlderNewer