From d72735e416946b84ff76d8d9c95fd48cbdfa347d Mon Sep 17 00:00:00 2001 From: Leons Aleksandrovs <58330666+Skrazzo@users.noreply.github.com> Date: Wed, 2 Jul 2025 15:32:59 +0300 Subject: [PATCH] Fetched users with python --- backend/.gitignore | 3 +++ backend/db/__init__.py | 0 backend/{ => db}/attendance.db | Bin backend/db/db.py | 11 +++++++++++ backend/db/users.py | 9 +++++++++ backend/main.py | 10 ++++++++++ backend/requirements.txt | 13 +++++++++++++ 7 files changed, 46 insertions(+) create mode 100644 backend/.gitignore create mode 100644 backend/db/__init__.py rename backend/{ => db}/attendance.db (100%) create mode 100644 backend/db/db.py create mode 100644 backend/db/users.py create mode 100644 backend/main.py create mode 100644 backend/requirements.txt diff --git a/backend/.gitignore b/backend/.gitignore new file mode 100644 index 0000000..062e3f6 --- /dev/null +++ b/backend/.gitignore @@ -0,0 +1,3 @@ +.venv +__pychace__/ +*.pyc diff --git a/backend/db/__init__.py b/backend/db/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/backend/attendance.db b/backend/db/attendance.db similarity index 100% rename from backend/attendance.db rename to backend/db/attendance.db diff --git a/backend/db/db.py b/backend/db/db.py new file mode 100644 index 0000000..6cbf20d --- /dev/null +++ b/backend/db/db.py @@ -0,0 +1,11 @@ +# This file is for database connection +import sqlite3 + +# Create the connection once, reuse it +# Check same thread is false, because we fast api runs on multiple threads +conn = sqlite3.connect("db/attendance.db", check_same_thread=False) +conn.row_factory = sqlite3.Row + +def get_db(): + return conn + diff --git a/backend/db/users.py b/backend/db/users.py new file mode 100644 index 0000000..ffdef6e --- /dev/null +++ b/backend/db/users.py @@ -0,0 +1,9 @@ +# This file is for database functions +from db.db import get_db + +def get_users(): + conn = get_db() + cursor = conn.cursor() + cursor.execute("SELECT * FROM Employees") + users = cursor.fetchall() + return users diff --git a/backend/main.py b/backend/main.py new file mode 100644 index 0000000..aa30b7b --- /dev/null +++ b/backend/main.py @@ -0,0 +1,10 @@ +from fastapi import FastAPI +import sqlite3 +from db.users import get_users + +# Get fastapi app +app = FastAPI() + +@app.get("/") +def list_users(): + return get_users() diff --git a/backend/requirements.txt b/backend/requirements.txt new file mode 100644 index 0000000..bf73abe --- /dev/null +++ b/backend/requirements.txt @@ -0,0 +1,13 @@ +annotated-types==0.7.0 +anyio==4.9.0 +click==8.2.1 +fastapi==0.115.14 +h11==0.16.0 +idna==3.10 +pydantic==2.11.7 +pydantic-core==2.33.2 +sniffio==1.3.1 +starlette==0.46.2 +typing-extensions==4.14.0 +typing-inspection==0.4.1 +uvicorn==0.35.0