surfiniaburger commited on
Commit
1a4a78f
·
1 Parent(s): c31173b
Files changed (1) hide show
  1. local_database.py +15 -3
local_database.py CHANGED
@@ -8,11 +8,13 @@ INDEX_FILE = "auramind_faiss.index"
8
  def get_db_connection():
9
  """Establishes a connection to the database."""
10
  conn = None
 
11
  try:
12
  conn = sqlite3.connect(DB_FILE)
13
  conn.row_factory = sqlite3.Row
 
14
  except Error as e:
15
- print(e)
16
  return conn
17
 
18
  def init_db():
@@ -20,9 +22,12 @@ def init_db():
20
  Initializes a more robust database schema for multimodal data.
21
  - 'documents' table tracks the source files.
22
  - 'chunks' table stores the individual encrypted text/image chunks.
 
23
  """
 
24
  conn = get_db_connection()
25
  if conn is None:
 
26
  return
27
  cursor = conn.cursor()
28
 
@@ -32,7 +37,9 @@ def init_db():
32
  id INTEGER PRIMARY KEY AUTOINCREMENT,
33
  name TEXT NOT NULL UNIQUE
34
  )
35
- ''')
 
 
36
 
37
  # Table to store each chunk of content (text or image)
38
  # The faiss_id will correspond to the row number in the FAISS index
@@ -45,7 +52,9 @@ def init_db():
45
  page_num INTEGER,
46
  FOREIGN KEY (doc_id) REFERENCES documents (id)
47
  )
48
- ''')
 
 
49
 
50
  # Table for farm analysis data
51
  sql_create_table = """ CREATE TABLE IF NOT EXISTS farm_analysis (
@@ -64,9 +73,12 @@ def init_db():
64
  outcome_image_id TEXT
65
  ); """
66
  cursor.execute(sql_create_table)
 
67
 
68
  conn.commit()
 
69
  conn.close()
 
70
 
71
  def check_if_indexed():
72
  """Checks if the initial database and index file exist."""
 
8
  def get_db_connection():
9
  """Establishes a connection to the database."""
10
  conn = None
11
+ print(f"Attempting to connect to database: {DB_FILE}")
12
  try:
13
  conn = sqlite3.connect(DB_FILE)
14
  conn.row_factory = sqlite3.Row
15
+ print(f"Successfully connected to database: {DB_FILE}")
16
  except Error as e:
17
+ print(f"Error connecting to database: {e}")
18
  return conn
19
 
20
  def init_db():
 
22
  Initializes a more robust database schema for multimodal data.
23
  - 'documents' table tracks the source files.
24
  - 'chunks' table stores the individual encrypted text/image chunks.
25
+ - 'farm_analysis' table stores analysis data.
26
  """
27
+ print("Initializing database...")
28
  conn = get_db_connection()
29
  if conn is None:
30
+ print("Database connection failed, cannot initialize.")
31
  return
32
  cursor = conn.cursor()
33
 
 
37
  id INTEGER PRIMARY KEY AUTOINCREMENT,
38
  name TEXT NOT NULL UNIQUE
39
  )
40
+ ''
41
+ )
42
+ print("Table 'documents' checked/created.")
43
 
44
  # Table to store each chunk of content (text or image)
45
  # The faiss_id will correspond to the row number in the FAISS index
 
52
  page_num INTEGER,
53
  FOREIGN KEY (doc_id) REFERENCES documents (id)
54
  )
55
+ ''
56
+ )
57
+ print("Table 'chunks' checked/created.")
58
 
59
  # Table for farm analysis data
60
  sql_create_table = """ CREATE TABLE IF NOT EXISTS farm_analysis (
 
73
  outcome_image_id TEXT
74
  ); """
75
  cursor.execute(sql_create_table)
76
+ print("Table 'farm_analysis' checked/created.")
77
 
78
  conn.commit()
79
+ print("Database changes committed.")
80
  conn.close()
81
+ print("Database connection closed.")
82
 
83
  def check_if_indexed():
84
  """Checks if the initial database and index file exist."""