V1.0.0.2 - Refactor: Split DB and Import logic, fixed CSV upload columns

This commit is contained in:
Javier
2026-01-22 01:47:35 -06:00
parent 4c5a588197
commit c747375f79
7 changed files with 188 additions and 147 deletions

26
db.py Normal file
View File

@@ -0,0 +1,26 @@
import sqlite3
from flask import current_app, g
def get_db():
"""Get database connection"""
# Use current_app.config to access settings from any module
conn = sqlite3.connect(current_app.config['DATABASE'])
conn.row_factory = sqlite3.Row
return conn
def query_db(query, args=(), one=False):
"""Query database helper"""
conn = get_db()
cursor = conn.execute(query, args)
rv = cursor.fetchall()
conn.close()
return (rv[0] if rv else None) if one else rv
def execute_db(query, args=()):
"""Execute database insert/update/delete"""
conn = get_db()
cursor = conn.execute(query, args)
conn.commit()
last_id = cursor.lastrowid
conn.close()
return last_id