-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.py
More file actions
31 lines (24 loc) · 918 Bytes
/
Copy pathdb.py
File metadata and controls
31 lines (24 loc) · 918 Bytes
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
import datetime
import sqlite3
from sqlite3 import Connection, Cursor
from config import settings
class DBService:
conn: Connection
cursor: Cursor
def __init__(self):
self.conn = sqlite3.connect(settings.DB_FILE)
self.cursor = self.conn.cursor()
self._create_table()
def _create_table(self) -> None:
self.cursor.execute(
"""CREATE TABLE IF NOT EXISTS server_events
(id INTEGER PRIMARY KEY AUTOINCREMENT, event_date TEXT)"""
)
self.conn.commit()
def get_last_event_date(self) -> str:
self.cursor.execute("SELECT MAX(event_date) FROM server_events")
last_event_date = self.cursor.fetchone()[0]
return last_event_date
def insert_failure_event(self) -> None:
self.cursor.execute("INSERT INTO server_events (event_date) VALUES (?)", (datetime.datetime.now(),))
self.conn.commit()