diff --git a/backend/__init__.py b/backend/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/backend/database.py b/backend/database.py new file mode 100644 index 0000000..967e99a --- /dev/null +++ b/backend/database.py @@ -0,0 +1,11 @@ +from sqlalchemy import create_engine +from sqlalchemy.orm import sessionmaker +from sqlalchemy.ext.declarative import declarative_base + +SQLALCHEMY_DATABASE_URL = 'sqlite:///./forum.db' + +engine = create_engine(SQLALCHEMY_DATABASE_URL, connect_args={'check_same_thread': False}) + +SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) + +Base = declarative_base() \ No newline at end of file diff --git a/backend/forum.db b/backend/forum.db new file mode 100644 index 0000000..d7baae5 Binary files /dev/null and b/backend/forum.db differ diff --git a/backend/forum.py b/backend/forum.py index 672b686..a526450 100644 --- a/backend/forum.py +++ b/backend/forum.py @@ -1,8 +1,12 @@ from fastapi import FastAPI +import models +from database import engine from pydantic import BaseModel app = FastAPI() +models.Base.metadata.create_all(bind=engine) + class Post: """Post is a single forum post or reply""" diff --git a/backend/models.py b/backend/models.py new file mode 100644 index 0000000..9f1f275 --- /dev/null +++ b/backend/models.py @@ -0,0 +1,21 @@ +from database import Base +from sqlalchemy import Column, Integer, String, Boolean, ForeignKey + + +class Posts(Base): + __tablename__ = 'posts' + + id = Column(Integer, primary_key=True) + thread_id = Column(Integer, ForeignKey("threads.id")) + author = Column(String) + title = Column(String) + content = Column(String) + + +class Threads(Base): + __tablename__ = 'threads' + + id = Column(Integer, primary_key=True) + author = Column(String) + title = Column(String) + content = Column(String) \ No newline at end of file diff --git a/backend/requirements.txt b/backend/requirements.txt index 364e2ee..09b688d 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -1,2 +1,3 @@ fastapi uvicorn[standard] +sqlalchemy