Spaces:
Build error
Build error
Update utils/database.py
Browse files218 unmodified lines219220221222223224218 unmodified linesst.error(f"Error recreating collections tables: {e}")return Falsedef get_all_documents(conn: sqlite3.Connection) -> List[Dict]:"""Get all documents with their metadata and collections."""218 unmodified lines219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292218 unmodified linesst.error(f"Error recreating collections tables: {e}")return Falsedef get_uncategorized_documents(conn: sqlite3.Connection) -> List[Dict]:"""Get documents that aren't in any collection."""try:with conn_lock:cursor = conn.cursor()cursor.execute('''SELECTd.id,d.name,d.content,d.upload_dateFROM documents dLEFT JOIN document_collections dc ON d.id = dc.document_idWHERE dc.collection_id IS NULLORDER BY d.upload_date DESC''')return [{'id': row[0],'name': row[1],'content': row[2],'upload_date': row[3],'collections': []} for row in cursor.fetchall()]except sqlite3.Error as e:st.error(f"Error retrieving uncategorized documents: {e}")return []def get_documents_for_chat(conn: sqlite3.Connection, collection_id: Optional[int] = None) -> List[Dict]:"""Get documents for chat, either from a collection or all documents."""try:with conn_lock:cursor = conn.cursor()if collection_id:cursor.execute('''SELECTd.id,d.name,d.content,d.upload_dateFROM documents dJOIN document_collections dc ON d.id = dc.document_idWHERE dc.collection_id = ?ORDER BY d.upload_date DESC''', (collection_id,))else:cursor.execute('''SELECTd.id,d.name,d.content,d.upload_dateFROM documents dORDER BY d.upload_date DESC''')return [{'id': row[0],'name': row[1],'content': row[2],'upload_date': row[3]} for row in cursor.fetchall()]except sqlite3.Error as e:st.error(f"Error retrieving documents for chat: {e}")return []def get_all_documents(conn: sqlite3.Connection) -> List[Dict]:"""Get all documents with their metadata and collections."""
utils/database.py+68