-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.py
More file actions
28 lines (24 loc) · 886 Bytes
/
database.py
File metadata and controls
28 lines (24 loc) · 886 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
import sqlite3
import pandas as pd
class DatabaseHandler:
def __init__(self, db_name="notes.db"):
self.conn = sqlite3.connect(db_name, check_same_thread=False)
self.create_table()
def create_table(self):
query = """
CREATE TABLE IF NOT EXISTS notes (
id INTEGER PRIMARY KEY AUTOINCREMENT,
content TEXT,
tag TEXT,
priority TEXT,
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
)
"""
self.conn.execute(query)
self.conn.commit()
def add_note(self, content, tag, priority):
query = "INSERT INTO notes (content, tag, priority) VALUES (?, ?, ?)"
self.conn.execute(query, (content, tag, priority))
self.conn.commit()
def fetch_all(self):
return pd.read_sql_query("SELECT * FROM notes ORDER BY timestamp DESC", self.conn)