more moving of files
This commit is contained in:
0
server/app/model/__init__.py
Normal file
0
server/app/model/__init__.py
Normal file
31
server/app/model/queries.py
Normal file
31
server/app/model/queries.py
Normal file
@@ -0,0 +1,31 @@
|
||||
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)
|
||||
Reference in New Issue
Block a user