Fetched users with python

This commit is contained in:
Leons Aleksandrovs
2025-07-02 15:32:59 +03:00
parent 9803b5b35d
commit d72735e416
7 changed files with 46 additions and 0 deletions

3
backend/.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
.venv
__pychace__/
*.pyc

0
backend/db/__init__.py Normal file
View File

11
backend/db/db.py Normal file
View File

@@ -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

9
backend/db/users.py Normal file
View File

@@ -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

10
backend/main.py Normal file
View File

@@ -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()

13
backend/requirements.txt Normal file
View File

@@ -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