Create database.py
Browse files- database.py +28 -0
database.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sqlite3
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
DB_PATH = "results.db"
|
| 5 |
+
|
| 6 |
+
# Agar database file exist nahi karti toh create karo
|
| 7 |
+
if not os.path.exists(DB_PATH):
|
| 8 |
+
conn = sqlite3.connect(DB_PATH)
|
| 9 |
+
cursor = conn.cursor()
|
| 10 |
+
cursor.execute('''
|
| 11 |
+
CREATE TABLE IF NOT EXISTS results (
|
| 12 |
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 13 |
+
api_name TEXT,
|
| 14 |
+
test_status TEXT,
|
| 15 |
+
run_timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
|
| 16 |
+
)
|
| 17 |
+
''')
|
| 18 |
+
conn.commit()
|
| 19 |
+
conn.close()
|
| 20 |
+
|
| 21 |
+
# Function to get past results
|
| 22 |
+
def show_past_results():
|
| 23 |
+
conn = sqlite3.connect(DB_PATH)
|
| 24 |
+
cursor = conn.cursor()
|
| 25 |
+
cursor.execute("SELECT * FROM results")
|
| 26 |
+
data = cursor.fetchall()
|
| 27 |
+
conn.close()
|
| 28 |
+
return data
|