|
|
|
|
|
from .session_state import initialize_session_state |
|
|
from .database import get_documents, insert_document |
|
|
|
|
|
__all__ = [ |
|
|
'initialize_session_state', |
|
|
'get_documents', |
|
|
'insert_document' |
|
|
] |
|
|
|
|
|
|
|
|
import streamlit as st |
|
|
import sqlite3 |
|
|
from datetime import datetime |
|
|
|
|
|
def get_documents(conn): |
|
|
"""Retrieve documents from database""" |
|
|
try: |
|
|
cursor = conn.cursor() |
|
|
cursor.execute("SELECT id, name, upload_date FROM documents ORDER BY upload_date DESC") |
|
|
return cursor.fetchall() |
|
|
except Exception as e: |
|
|
st.error(f"Error retrieving documents: {e}") |
|
|
return [] |
|
|
|
|
|
def insert_document(conn, doc_name, doc_content): |
|
|
"""Insert a document into database""" |
|
|
try: |
|
|
cursor = conn.cursor() |
|
|
cursor.execute("SELECT id FROM documents WHERE name = ?", (doc_name,)) |
|
|
if not cursor.fetchone(): |
|
|
conn.execute( |
|
|
"INSERT INTO documents (name, content) VALUES (?, ?)", |
|
|
(doc_name, doc_content) |
|
|
) |
|
|
return True |
|
|
except Exception as e: |
|
|
st.error(f"Error inserting document: {e}") |
|
|
return False |
|
|
|