-
Notifications
You must be signed in to change notification settings - Fork 1
/
db.py
59 lines (53 loc) · 1.69 KB
/
db.py
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
51
52
53
54
55
56
57
58
59
import sqlite3
import os
def get_db_connection():
db_path = os.path.abspath(os.getcwd()) + "/github_issues.db"
connection = sqlite3.connect(db_path)
return connection
def create_tables():
connection = get_db_connection()
cursor = connection.cursor()
cursor.execute("""
CREATE TABLE IF NOT EXISTS issues_table (
id INTEGER PRIMARY KEY AUTOINCREMENT,
issue_number INTEGER,
title TEXT,
description TEXT,
recommendation TEXT
)
""")
connection.commit()
connection.close()
def insert_issue_data(issue_number, title, description, recommendation):
connection = get_db_connection()
cursor = connection.cursor()
cursor.execute("""
INSERT INTO issues_table (issue_number, title, description, recommendation)
VALUES (?, ?, ?, ?)
""", (issue_number, title, description, recommendation))
connection.commit()
connection.close()
def get_all_issues_data():
connection = get_db_connection()
cursor = connection.cursor()
cursor.execute("SELECT * FROM issues_table")
rows = cursor.fetchall()
connection.close()
return rows
def get_issue_by_number(issue_number):
connection = get_db_connection()
cursor = connection.cursor()
cursor.execute("SELECT * FROM issues_table WHERE issue_number = ?", (issue_number,))
row = cursor.fetchone()
connection.close()
return row
def update_recommendation(issue_number, recommendation):
connection = get_db_connection()
cursor = connection.cursor()
cursor.execute("""
UPDATE issues_table
SET recommendation = ?
WHERE issue_number = ?
""", (recommendation, issue_number))
connection.commit()
connection.close()