38 lines
1.1 KiB
Python
38 lines
1.1 KiB
Python
import sqlite3
|
|
from pathlib import Path
|
|
import pandas as pd
|
|
|
|
BASE_DIR = Path(__file__).resolve().parent
|
|
# DB_PATH = BASE_DIR / "app_db" / "app.db"
|
|
DB_PATH = BASE_DIR / "app.db"
|
|
|
|
|
|
#-------------------------------------------------------------------------------------
|
|
# Allgemeine Datenbankfunktionen
|
|
#-------------------------------------------------------------------------------------
|
|
|
|
def get_conn():
|
|
# check_same_thread=False, damit Streamlit mehrere Threads nutzen kann
|
|
return sqlite3.connect(DB_PATH, check_same_thread=False)
|
|
|
|
def get_list(sql, params=None):
|
|
conn = get_conn()
|
|
df = pd.read_sql_query(sql, conn, params=params)
|
|
conn.close()
|
|
return df
|
|
|
|
def send_cmd(sql, params=None):
|
|
try:
|
|
with get_conn() as conn:
|
|
if params is None:
|
|
conn.execute(sql)
|
|
else:
|
|
conn.execute(sql, params)
|
|
return True
|
|
except Exception as e:
|
|
print("DB-Fehler:", e)
|
|
return False
|
|
|
|
#-------------------------------------------------------------------------------------
|
|
#
|
|
#------------------------------------------------------------------------------------- |