FastAPI(2)
-
FastAPI에 모델 (Model) 적용
FastAPI에 모델 (Model) 적용 sqlacodegen을 이용하면 모델 생성 알아서 해줌 pip install sqlacodegen sqlacodegen mysql+pymysql://:@:/ > "./models.py" 결과 # coding: utf-8 from sqlalchemy import Column, ForeignKey, Integer, String from sqlalchemy.orm import relationship from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() metadata = Base.metadata class User(Base): __tablename__ = 'user' UID =..
2023.03.29 -
FastAPI로 CRUD, ORM sqlalchemy 사용, 캐쉬 예시 예제
FastAPI로 CRUD, ORM sqlalchemy 사용, 캐쉬 예시 예제 FastAPI로 CRUD 모듈 설치 pip install fastapi pip install "uvicorn[standard]" pip install requests pip install pydantic 코드 작성 from fastapi import FastAPI, HTTPException from pydantic import BaseModel from typing import Optional import requests app = FastAPI() # this is list now, but it's gonna real database like mongoDB db = [] # class must be pydantic field ..
2023.03.28