Fetched users with python
This commit is contained in:
3
backend/.gitignore
vendored
Normal file
3
backend/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
.venv
|
||||
__pychace__/
|
||||
*.pyc
|
||||
0
backend/db/__init__.py
Normal file
0
backend/db/__init__.py
Normal file
11
backend/db/db.py
Normal file
11
backend/db/db.py
Normal 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
9
backend/db/users.py
Normal 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
10
backend/main.py
Normal 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
13
backend/requirements.txt
Normal 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
|
||||
Reference in New Issue
Block a user