cryogenic22 commited on
Commit
35cf712
·
verified ·
1 Parent(s): 816cc2d

Update utils/database.py

Browse files
Files changed (1) hide show
  1. utils/database.py +25 -0
utils/database.py CHANGED
@@ -95,6 +95,31 @@ def get_documents(conn):
95
  except Error as e:
96
  st.error(f"Error retrieving documents: {e}")
97
  return [], []
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98
  # QA system initialization function with necessary updates
99
  def initialize_qa_system(vector_store):
100
  """Initialize QA system with proper chat handling."""
 
95
  except Error as e:
96
  st.error(f"Error retrieving documents: {e}")
97
  return [], []
98
+
99
+ def insert_document(conn, name, content):
100
+ """Insert a new document into the database.
101
+
102
+ Args:
103
+ conn: SQLite database connection
104
+ name (str): Name of the document
105
+ content (str): Content of the document
106
+
107
+ Returns:
108
+ int: ID of the inserted document, or None if insertion failed
109
+ """
110
+ try:
111
+ cursor = conn.cursor()
112
+ sql = '''INSERT INTO documents (name, content)
113
+ VALUES (?, ?)'''
114
+ cursor.execute(sql, (name, content))
115
+ conn.commit()
116
+ return cursor.lastrowid
117
+
118
+ except Error as e:
119
+ st.error(f"Error inserting document: {e}")
120
+ return None
121
+
122
+
123
  # QA system initialization function with necessary updates
124
  def initialize_qa_system(vector_store):
125
  """Initialize QA system with proper chat handling."""