-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_database.py
More file actions
38 lines (31 loc) · 1.11 KB
/
check_database.py
File metadata and controls
38 lines (31 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import sqlite3
import os
# Set environment variables for local development
os.environ["INPUT_DIR"] = os.path.join(os.getcwd(), "input")
os.environ["OUTPUT_DIR"] = os.path.join(os.getcwd(), "output")
# Now import settings after environment variables are set
from refiner.config import settings
# Connect to the database
db_path = os.path.join(settings.OUTPUT_DIR, 'db.libsql')
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
# List all tables
cursor.execute("SELECT name FROM sqlite_master WHERE type='table';")
tables = cursor.fetchall()
print("Tables in the database:")
for table in tables:
print(f"- {table[0]}")
# For each table, show its structure and some data
for table in tables:
table_name = table[0]
print(f"\nTable structure {table_name}:")
cursor.execute(f"PRAGMA table_info({table_name});")
columns = cursor.fetchall()
for column in columns:
print(f" {column[1]} ({column[2]})")
print(f"\nSample data from {table_name}:")
cursor.execute(f"SELECT * FROM {table_name} LIMIT 5;")
rows = cursor.fetchall()
for row in rows:
print(f" {row}")
conn.close()