-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.py
More file actions
50 lines (42 loc) · 1.42 KB
/
Copy pathdatabase.py
File metadata and controls
50 lines (42 loc) · 1.42 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
39
40
41
42
43
44
45
46
47
48
49
50
import sqlite3
from typing import List, Dict, Any
DB_FILE = "research.db"
def get_db_connection():
conn = sqlite3.connect(DB_FILE)
conn.row_factory = sqlite3.Row
return conn
def create_research_plans_table():
conn = get_db_connection()
cursor = conn.cursor()
cursor.execute("""
CREATE TABLE IF NOT EXISTS research_plans (
id INTEGER PRIMARY KEY,
short_summary TEXT NOT NULL,
details TEXT NOT NULL
)
""")
conn.commit()
conn.close()
def get_research_plans() -> List[Dict[str, Any]]:
conn = get_db_connection()
cursor = conn.cursor()
cursor.execute("SELECT * FROM research_plans")
research_plans = [dict(row) for row in cursor.fetchall()]
conn.close()
return research_plans
def add_research_plan(short_summary: str, details: str) -> Dict[str, Any]:
conn = get_db_connection()
cursor = conn.cursor()
cursor.execute("INSERT INTO research_plans (short_summary, details) VALUES (?, ?)", (short_summary, details))
research_plan_id = cursor.lastrowid
conn.commit()
conn.close()
return {"id": research_plan_id, "short_summary": short_summary, "details": details}
def delete_research_plan(research_plan_id: int):
conn = get_db_connection()
cursor = conn.cursor()
cursor.execute("DELETE FROM research_plans WHERE id = ?", (research_plan_id,))
conn.commit()
conn.close()
def init_db():
create_research_plans_table()