ATS-Doku/data/data_api.py
2026-05-05 13:31:03 +00:00

70 lines
1.9 KiB
Python

import sqlite3
from data.database import DB_NAME
def add_data_to_einsaetze(name, location, date, time, etype, device):
connection = sqlite3.connect(DB_NAME)
cursor = connection.cursor()
sql_query = "INSERT INTO einsaetze (name, location, date, time, etype, device) VALUES (?, ?, ?, ?, ?, ?)"
data = (name, location, date, time, etype, device)
cursor.execute(sql_query, data)
connection.commit()
connection.close()
def get_ats_names():
connection = sqlite3.connect(DB_NAME)
cursor = connection.cursor()
# nur die Spalte 'name' aus der Tabelle 'ats'
cursor.execute("SELECT name FROM ats ORDER BY name ASC")
names = cursor.fetchall()
connection.close()
return [row[0] for row in names]
def get_entrys():
connection = sqlite3.connect(DB_NAME)
#Get Data an Row Names
connection.row_factory = sqlite3.Row
cursor = connection.cursor()
cursor.execute('''
SELECT e.id, e.date, w.name, e.location, e.time, e.etype, d.name
FROM entrys e
LEFT JOIN ba_wearer w ON e.wearer_id = w.id
LEFT JOIN ba_devices d ON e.device_id = d.id
''')
data = cursor.fetchall()
connection.close()
d = [dict(row) for row in data]
print (d)
return d
# ATS Träger aus DB Löschen ODER einfügen.abs
def delete_ats_traeger(id):
connection = sqlite3.connect(DB_NAME)
cursor = connection.cursor()
def get_ats_with_id():
#Verbindung Aufbauen
connection = sqlite3.connect(DB_NAME)
connection.row_factory = sqlite3.Row
cursor = connection.cursor()
cursor.execute("SELECT id, name FROM ats ORDER BY name ASC")
data = cursor.fetchall()
return [dict(row) for row in data]
def delete_entry(entry_id):
connection = sqlite3.connect(DB_NAME)
cursor = connection.cursor()
cursor.execute("DELETE FROM entrys WHERE id = ?", (entry_id,))
connection.commit()