Files
LucasJensen/server/app/model/queries.py
2024-07-06 10:57:10 -07:00

32 lines
926 B
Python

from app.utils.db import connect_db
from app.types import About, Project
def get_projects() -> list[Project]:
db = connect_db()
cursor = db.cursor(dictionary=True)
cursor.execute("SELECT * FROM projects")
data = cursor.fetchall()
projects = [Project(**p) for p in data] # type: ignore
db.close()
return projects
def get_project(project_id: int) -> Project | None:
db = connect_db()
cursor = db.cursor(dictionary=True)
cursor.execute("SELECT * FROM projects WHERE id=%s", (project_id,))
data = cursor.fetchone()
db.close()
return None if data is None else Project(**data) # type: ignore
def get_about() -> About:
db = connect_db()
cursor = db.cursor(dictionary=True)
cursor.execute("SELECT name, email, bio, github, gitea FROM self")
data = {key: val for key, val in cursor.fetchone().items()} # type: ignore
db.close()
return About(**data)