Compare commits
No commits in common. "a33e349f6304083263bd4b95ab1e08ebb35b0a40" and "5b633c8f42991a9c9da01e1fff3d2bcbf358cd6d" have entirely different histories.
a33e349f63
...
5b633c8f42
@ -52,9 +52,9 @@ def delete_user(id: int):
|
|||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
def create_habit(user_id: int, name: str, times: int, unit: int, slot: int, note: str | None=None):
|
def create_habit(name: str, user_id: int, times: int, unit: int, slot: int, note: str | None=None):
|
||||||
now = datetime.now().isoformat()
|
now = datetime.now().isoformat()
|
||||||
query = (f"INSERT INTO habits (user_id, name, note, times, unit, slot, created_at, updated_at) VALUES ('{user_id}', "
|
query = (f"INSERT INTO habits (user_id, name, note, times, unit, list_index, created_at, updated_at) VALUES ('{user_id}', "
|
||||||
f"'{name}', '{note}', '{times}', '{unit}', '{slot}', '{now}', '{now}');")
|
f"'{name}', '{note}', '{times}', '{unit}', '{slot}', '{now}', '{now}');")
|
||||||
conn = con3()
|
conn = con3()
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
@ -63,7 +63,6 @@ def create_habit(user_id: int, name: str, times: int, unit: int, slot: int, note
|
|||||||
conn.close()
|
conn.close()
|
||||||
return cursor.lastrowid
|
return cursor.lastrowid
|
||||||
|
|
||||||
|
|
||||||
def get_next_slot():
|
def get_next_slot():
|
||||||
query = f"SELECT slot FROM habits ORDER BY slot DESC LIMIT 1;"
|
query = f"SELECT slot FROM habits ORDER BY slot DESC LIMIT 1;"
|
||||||
conn = con3()
|
conn = con3()
|
||||||
@ -101,34 +100,3 @@ def delete_habit(id: int):
|
|||||||
cursor.execute(query)
|
cursor.execute(query)
|
||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
def create_habitTrackings(habit_id: int, times: int):
|
|
||||||
now = datetime.now().isoformat()
|
|
||||||
query = (
|
|
||||||
f"INSERT INTO habit_trackings (habit_id, times, created_at) VALUES ('{habit_id}', '{times}','{now}');")
|
|
||||||
conn = con3()
|
|
||||||
cursor = conn.cursor()
|
|
||||||
cursor.execute(query)
|
|
||||||
conn.commit()
|
|
||||||
conn.close()
|
|
||||||
return cursor.lastrowid
|
|
||||||
|
|
||||||
|
|
||||||
def get_habitTrackings(id: int):
|
|
||||||
query = f"SELECT * FROM habit_trackings WHERE id = {id};"
|
|
||||||
conn = con3()
|
|
||||||
cursor = conn.cursor()
|
|
||||||
cursor.execute(query)
|
|
||||||
habit_tracking = cursor.fetchone()
|
|
||||||
conn.close()
|
|
||||||
return habit_tracking
|
|
||||||
|
|
||||||
|
|
||||||
def delete_habitTrackings(id: int):
|
|
||||||
query = f"DELETE FROM habit_trackings WHERE id = {id};"
|
|
||||||
conn = con3()
|
|
||||||
cursor = conn.cursor()
|
|
||||||
cursor.execute(query)
|
|
||||||
conn.commit()
|
|
||||||
conn.close()
|
|
||||||
|
|||||||
@ -1,8 +0,0 @@
|
|||||||
CREATE TABLE IF NOT EXISTS habit_trackings
|
|
||||||
(
|
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
||||||
habit_id INTEGER,
|
|
||||||
times INTEGER NOT NULL,
|
|
||||||
created_at TEXT NOT NULL,
|
|
||||||
FOREIGN KEY (habit_id) REFERENCES habits(id)
|
|
||||||
);
|
|
||||||
@ -1,23 +0,0 @@
|
|||||||
from dataclasses import dataclass
|
|
||||||
from db.SQLiteClient import create_habitTrackings, get_habitTrackings, delete_habitTrackings
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class HabitTrackings:
|
|
||||||
id: int
|
|
||||||
habit_id: int
|
|
||||||
times: int
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def create(habit_id: int, times: int):
|
|
||||||
id = create_habitTrackings(habit_id, times)
|
|
||||||
return HabitTrackings(id, habit_id, times)
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get(id: int):
|
|
||||||
habitTrackings = get_habitTrackings(id)
|
|
||||||
return HabitTrackings(habitTrackings[0], habitTrackings[1], habitTrackings[2]) if habitTrackings else None
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def delete(id: int):
|
|
||||||
delete_habitTrackings(id)
|
|
||||||
Loading…
x
Reference in New Issue
Block a user